Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AGCAuthService

Hierarchy

Index

Properties

Private cls_ServiceAGCAuth

cls_ServiceAGCAuth: string = "org/cocos2dx/javascript/service/ServiceAGCAuth"

listener

listener: AuthListener = null

support

support: boolean

Methods

deleteUser

  • deleteUser(): void
  • en

    Deletes the current user information and cache information from the AppGallery Connect server.

    zh

    在 AppGallery Connect 服务器端删除当前用户信息,同时清除缓存信息。

    example
    huawei.agc.auth.authService.deleteUser();
    

    Returns void

getSupportAuthType

  • getSupportAuthType(): string
  • en

    Get supported authentication methods, such as "[0, 1, 2]", refer to AuthProvider type.

    zh

    获取支持的认证登录方式,例如 "[0, 1, 2]"。枚举值对应 AuthProvider。

    example
    let supAuthType = huawei.agc.auth.authService.getSupportAuthType();
    console.log("getSupportAuthType...", "type = ", supAuthType);
    

    Returns string

getToken

  • getToken(forceRefresh: boolean): void
  • en

    Obtains the Access Token of a user from AppGallery Connect, update results via the asynchronous callback. Callback code is huawei.agc.auth.AuthRetCode.GET_TOKEN_SUCCESS or huawei.agc.auth.AuthRetCode.GET_TOKEN_FAIL.

    zh

    获取用户的 Access Token 信息。通过异步回调更新结果。回调 Code 为 huawei.agc.auth.AuthRetCode.GET_TOKEN_SUCCESShuawei.agc.auth.AuthRetCode.GET_TOKEN_FAIL

    example
    huawei.agc.auth.authService.getToken(true);
    

    Parameters

    • forceRefresh: boolean

      Indicates whether to forcibly update the Access Token for new users.

    Returns void

getUserExtra

  • getUserExtra(): void
  • en

    Obtains UserExtra of the current user, update results via the asynchronous callback. This API verifies the Access Token and Refresh Token of a user. Ensure that the Refresh Token is within its validity period. Otherwise, result code INVALID_REFRESH_TOKEN = 203817986 will be returned, indicating that the user's Refresh Token has expired.

    zh

    获取当前用户的 UserExtra,通过异步回调更新结果。此接口会验证用户 Access Token 和 Refresh Token,请确保用户 Refresh Token 在有效期内,否则会抛出错误码 INVALID_REFRESH_TOKEN = 203817986,表示用户 Refresh Token 无效错误码。开发者收到此错误码后,应该让用户重新登录,获取新的 Access Token 和 Refresh Token。

    example
    huawei.agc.auth.authService.getUserExtra();
    

    Returns void

getUserInfo

  • getUserInfo(): any
  • en

    Get current user info.

    zh

    获取当前用户信息

    example
    let userInfo = huawei.agc.auth.authService.getUserInfo();
    console.log('getUserInfo...', 'info =', JSON.stringify(userInfo));
    

    Returns any

getVerifyCode

  • getVerifyCode(): void
  • en

    get verify code (for Email or Phone provider)

    zh

    获取验证码(邮箱或手机认证登录方式)

    example
    huawei.agc.auth.authService.getVerifyCode();
    

    Returns void

link

  • en

    Associate a new authentication login method for the current user.

    zh

    为当前用户关联新的认证登录方式

    example
    huawei.agc.auth.authService.link(huawei.agc.auth.AuthProvider.HMS_Provider);
    

    Parameters

    • authType: AuthProvider

      enumeration value of AuthProvider type

    Returns void

login

  • login(): void
  • en

    Call the login method of the current authentication method.

    zh

    调用当前认证登录方式的 登录 方法

    example
    huawei.agc.auth.authService.login();
    

    Returns void

logout

  • logout(): void
  • en

    Call the logout method of the current authentication method.

    zh

    调用当前认证登录方式的 登出 方法

    example
    huawei.agc.auth.authService.logout();
    

    Returns void

register

  • register(): void
  • en

    User register (for phone number or email account authentication methods only).

    zh

    用户注册(邮箱或手机认证登录方式)

    example
    huawei.agc.auth.authService.register();
    

    Returns void

resetPassword

  • resetPassword(emailOrPhone: string, newPassword: string, verifyCode: string, countryCode?: string): void
  • en

    Resets the password using a phone number (for phone number or email account authentication methods only). If the countryCode parameter is sent, it is the phone number authentication method, otherwise it is email account authentication method. Callback code is huawei.agc.auth.AuthRetCode.RESET_PASS_SUCCESS or huawei.agc.auth.AuthRetCode.RESET_PASS_FAIL.

    zh

    重置密码(邮箱或手机认证登录方式)。若传入 countryCode 参数则为手机认证登录方式,不传则为邮箱认证登录方式。回调 Code 为 huawei.agc.auth.AuthRetCode.RESET_PASS_SUCCESShuawei.agc.auth.AuthRetCode.RESET_PASS_FAIL

    example
    huawei.agc.auth.authService.resetPassword("132xxxxxxxx", "neWPaSSwOrd", "1234", "0086");
    huawei.agc.auth.authService.resetPassword("newUser1#gmail.com", "neWPaSSwOrd", "1234"); // replace `#` to `@`
    

    Parameters

    • emailOrPhone: string

      Email account or phone number.

    • newPassword: string

      New password.

    • verifyCode: string

      Verification code.

    • Default value countryCode: string = ""

      Country/Region code. For example, 86 indicates China, 49 indicates Germany, 7 indicates Russia, and 65 indicates Singapore. This parameter supports multiple formats. Taking China as an example, the code can be 86, 0086, or +86.

    Returns void

setAuthListener

  • en

    set the listener for auth

    zh

    设置认证服务监听

    example
    huawei.agc.auth.authService.setAuthListener(this.onAuthResult, this));
    
    onAuthResult: function (code, msg) {
        switch (code) {
            ...
        }
    }
    

    Parameters

    Returns void

setLoginInfo

  • setLoginInfo(loginInfo: any): void
  • en

    Set user registration or login information (for phone number or email account authentication methods only), the method needs to be called before other methods.

    zh

    设置用户注册或登录信息(邮箱或手机认证登录方式),该方法需要在其他方法前调用。

    example
    let loginInfo = {
       email: '953xxxxx#gmail.com',  // email provider required, replace `#` to `@`
       phoneNumber: "181XXXXXXXX",   // phone provider required
       countryCode: "86",            // phone provider required
       verifyCode: code,             // after `register` or `getVerifyCode` called, reset login info with verify code
       action: "register",           // `register` or `reset`
       locale: "zh",                 // language tag, optional, use system language by default
    }
    huawei.agc.auth.authService.setLoginInfo(loginInfo);
    

    Parameters

    • loginInfo: any

      JSON Object, according to the needs of phone or email account authentication method.

    Returns void

switchAuthType

  • en

    Select the current authentication method. You need to call this method first, before calling other methods such as login.

    zh

    选取当前认证登录方式。需要先调用该方法,才能调用 login 等方法。

    example
    huawei.agc.auth.authService.switchAuthType(huawei.agc.auth.AuthProvider.HMS_Provider);
    

    Parameters

    • authType: AuthProvider

      enumeration value of AuthProvider type

    Returns void

unlink

  • en

    Disassociates the current user from the associated login method.

    zh

    当前用户解除关联的登录方式。

    example
    huawei.agc.auth.authService.unlink(huawei.agc.auth.AuthProvider.HMS_Provider);
    

    Parameters

    Returns void

updateEmail

  • updateEmail(newEmail: string, newVerifyCode: string): void
  • en

    Updates the email account of the current user, update results via the asynchronous callback. Before calling this interface, call getVerifyCode function to apply a verification code for the new phone number to make sure the new number is owned by the current user.

    zh

    更新当前用户邮箱。通过异步回调更新结果。调用此接口之前,请调用 getVerifyCode 方法来为新邮箱申请验证码,从而确定新邮箱为该用户所有。

    example
    huawei.agc.auth.authService.updateEmail("newUser1#gmail.com", "1234"); // replace `#` to `@`
    

    Parameters

    • newEmail: string

      New email account.

    • newVerifyCode: string

      Verification code.

    Returns void

updatePassword

  • updatePassword(newPassword: string, verifyCode: string, provider: AuthProvider): void
  • en

    Updates the current user's password, update results via the asynchronous callback. After the password is updated successfully, the user's Access Token is refreshed and the user is asked to re-sign in. Otherwise, the API call may fail due to the Access Token matching failure.

    zh

    更新当前用户的密码,通过异步回调更新结果。密码更新成功后,用户的 Access Token 将会刷新,请用户重新登录,否则会出现 Access Token 不匹配而调用接口失败。

    example
    huawei.agc.auth.authService.updatePassword("neWPaSSwOrd", "1234", huawei.agc.auth.AuthProvider.Phone_Provider);
    

    Parameters

    • newPassword: string

      New password.

    • verifyCode: string

      Verification code.

    • provider: AuthProvider

      Enumeration value of AuthProvider type, which is used to distinguish the email account from the phone number account.

    Returns void

updatePhone

  • updatePhone(countryCode: string, phoneNumber: string, newVerifyCode: string): void
  • en

    Updates the phone number of the current user, update results via the asynchronous callback. Before calling this method, call the getVerifyCode function to apply for a verification code of the new email account. The verification code is used to verify that the current user owns the new email account.

    zh

    更新当前用户手机号。通过异步回调更新结果。调用此接口之前,请调用 getVerifyCode 方法来为新手机申请验证码,从而确定新手机为该用户所有。

    example
    huawei.agc.auth.authService.updateEmail("0086", "132xxxxxxxx", "1234");
    

    Parameters

    • countryCode: string

      Country/Region code. For example, 86 indicates China, 49 indicates Germany, 7 indicates Russia, and 65 indicates Singapore. This parameter supports multiple formats. Taking China as an example, the code can be 86, 0086, or +86.

    • phoneNumber: string

      Phone number. The number does not include the plus sign (+) and country/region code. For example, for the phone number +86132xxxxxxxx, the value of this parameter is 132xxxxxxxx.

    • newVerifyCode: string

      Verification code.

    Returns void

updateProfile

  • updateProfile(displayName: string, photoUrl: string): void
  • en

    Updates information (profile image and nickname) for the current user. This API verifies the Access Token and Refresh Token of a user. Ensure that the Refresh Token is within its validity period. Otherwise, result code INVALID_REFRESH_TOKEN = 203817986 will be returned, indicating that the user's Refresh Token has expired. When receiving the result code, prompt your user to sign in again so that you can obtain the new Access Token and Refresh Token.

    zh

    更新当前用户的个人信息(图像和昵称)。 此接口会验证用户 Access Token 和 Refresh Token,请确保用户 Refresh Token 在有效期内,否则会抛出 INVALID_REFRESH_TOKEN = 203817986(用户 Refresh Token 无效错误码)。开发者收到此错误码后,应该让用户重新登录,获取新的 Access Token 和 Refresh Token。

    example
    huawei.agc.auth.authService.updateProfile("name1", photoUrl);
    

    Parameters

    • displayName: string

      Display/nick name.

    • photoUrl: string

      Icon photo url.

    Returns void

Static callStaticMethod

  • callStaticMethod(...args: (number | boolean | string)[]): any

Generated using TypeDoc