HarmonyOS5 Cloud Service Technology Sharing – Authentication Documentation Issues

Hello, fellow developers! This article will provide a detailed guide on how to integrate Huawei AppGallery Connect (AGC) Authentication Service based on the HarmonyOS ArkTS framework, covering the entire process from project creation to SDK integration…


This content originally appeared on DEV Community and was authored by 陈杨

Hello, fellow developers! This article will provide a detailed guide on how to integrate Huawei AppGallery Connect (AGC) Authentication Service based on the HarmonyOS ArkTS framework, covering the entire process from project creation to SDK integration. Whether you are accessing AGC services for the first time or need to optimize an existing process, this article offers a complete guide.

I. Detailed Development Flow

1. Create Project and App

Purpose: A project is an organizational entity for AGC resources, supporting centralized management of different platform versions (e.g., mobile, tablet) of the same application.

Scenario Suggestions:

  • Use different projects to distinguish between testing and production environments.
  • Each project can independently manage different versions of authentication service configurations.

2. Enable Authentication Service

Log in to the AGC console, navigate to the target project, and on the "Build > Authentication Service" page, enable the desired authentication methods (e.g., mobile phone, email, Huawei ID, etc.).

3. Get the agconnect-services.json file

Path: AGC Console → Project settings → App information → Download configuration file.
Purpose: This file contains the necessary keys and configuration information for communication between the application and AGC services.

4. Integrate the SDK

Core Dependencies: AGC SDK + Authentication Service SDK.

Detailed Steps:

  • Configure HarmonyOS project dependencies (see the "SDK Integration" section below).
  • Initialize the SDK and add network permissions.

5. Implement Account Login and Authentication

Supported Methods:

  • Standard Login: Mobile phone, email, Huawei ID, self-owned account, anonymous account.

Advanced Features:

  • Account Linking: Supports linking multiple account systems to the same user identity.
  • Anonymous to Official: Upgrade an anonymous user to a registered account.

6. Sign Out

Function Description:

  • Clears local user information and Token. Applicable Scenarios: When a user switches accounts or temporarily logs out.

7. Delete Account

Security Requirements:

  • Users must initiate the account deletion themselves to ensure compliance with privacy regulations.
  • After account deletion, the user data on the AGC side will be permanently deleted.

II. Full SDK Integration Process

Prerequisites

  • Development Tool: DevEco Studio 5.0.3.100+
  • SDK Version:
    • Compile SDK Version ≥ 12
    • Compatible SDK Version ≥ 12

1. Add Application Configuration File

Copy agconnect-services.json to the project directory:
AppScope/resources/rawfile/
Note: If the rawfile directory does not exist, you need to create it manually.

2. Configure SDK Dependencies

Method 1: Via oh-package.json5
Add the dependency in the app-level oh-package.json5:

"dependencies": {
  "@hw-agconnect/auth": "^1.0.4"
}

Click "Sync Now" in the upper right corner to sync the configuration.

Method 2: Command-line Installation
Enter the entry directory and execute the command:

ohpm install @hw-agconnect/auth

3. Initialize the SDK

Initialize in onCreate of EntryAbility.ets:

import auth from '@hw-agconnect/auth';

onCreate(want, launchParam) {
  // Read the configuration file
  let file = this.context.resourceManager.getRawFileContentSync('agconnect-services.json');
  let json: string = buffer.from(file.buffer).toString();
  // Initialize the AGC SDK
  auth.init(this.context, json);
}

Add network permission:
Declare in module.json5:

"requestPermissions": [
  { "name": "ohos.permission.INTERNET" }
]

4. Manually Set Client ID/Secret (Optional)

Applicable Scenario: When the configuration file does not contain the key (the "Do not include key" option was checked during download).

Steps:

  1. Get the Client ID and Secret from "Project settings > General" in the AGC console.
  2. Add the parameters after initialization:
auth.setClientId("xxx");  // Replace with the actual value
auth.setClientSecret("xxx");

5. Configure Obfuscation Rules

Rules file: entry/obfuscation-rules.txt

Add content:

-keep
XXX/oh_modules/@hw-agconnect/auth

Path description: XXX is the actual path of the SDK in oh_modules (e.g., entry/oh_modules).

III. Conclusion

By following this article, you have completed the integration of AGC Authentication Service for HarmonyOS ArkTS. Subsequently, you can expand the login methods based on business needs (e.g., third-party social accounts) and monitor user behavior data through the AGC console. If you encounter any problems during practice, feel free to visit the Huawei Developer Forum or the official AGC documentation for technical support.

If there are other features you'd like to know about, please let me know in the comments! See you next time~ 👋


This content originally appeared on DEV Community and was authored by 陈杨


Print Share Comment Cite Upload Translate Updates
APA

陈杨 | Sciencx (2025-06-25T08:36:05+00:00) HarmonyOS5 Cloud Service Technology Sharing – Authentication Documentation Issues. Retrieved from https://www.scien.cx/2025/06/25/harmonyos5-cloud-service-technology-sharing-authentication-documentation-issues/

MLA
" » HarmonyOS5 Cloud Service Technology Sharing – Authentication Documentation Issues." 陈杨 | Sciencx - Wednesday June 25, 2025, https://www.scien.cx/2025/06/25/harmonyos5-cloud-service-technology-sharing-authentication-documentation-issues/
HARVARD
陈杨 | Sciencx Wednesday June 25, 2025 » HarmonyOS5 Cloud Service Technology Sharing – Authentication Documentation Issues., viewed ,<https://www.scien.cx/2025/06/25/harmonyos5-cloud-service-technology-sharing-authentication-documentation-issues/>
VANCOUVER
陈杨 | Sciencx - » HarmonyOS5 Cloud Service Technology Sharing – Authentication Documentation Issues. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/06/25/harmonyos5-cloud-service-technology-sharing-authentication-documentation-issues/
CHICAGO
" » HarmonyOS5 Cloud Service Technology Sharing – Authentication Documentation Issues." 陈杨 | Sciencx - Accessed . https://www.scien.cx/2025/06/25/harmonyos5-cloud-service-technology-sharing-authentication-documentation-issues/
IEEE
" » HarmonyOS5 Cloud Service Technology Sharing – Authentication Documentation Issues." 陈杨 | Sciencx [Online]. Available: https://www.scien.cx/2025/06/25/harmonyos5-cloud-service-technology-sharing-authentication-documentation-issues/. [Accessed: ]
rf:citation
» HarmonyOS5 Cloud Service Technology Sharing – Authentication Documentation Issues | 陈杨 | Sciencx | https://www.scien.cx/2025/06/25/harmonyos5-cloud-service-technology-sharing-authentication-documentation-issues/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.