HarmonyOS 华为账号登陆没有返回openid和unionid?

import { authentication, loginComponentManager, LoginWithHuaweiIDButton } from '@kit.AccountKit'
import { Logger } from '@ohos/base'
import { showToast } from '../../component/NiceToast'
import { BusinessError } from '@kit.BasicServicesKit'
import { util } from '@kit.ArkTS'

@Entry
@Component
struct LoginTestPage {
  private _loginController: loginComponentManager.LoginWithHuaweiIDButtonController =
    new loginComponentManager.LoginWithHuaweiIDButtonController().onClickLoginWithHuaweiIDButton((error: BusinessError,
      response: loginComponentManager.HuaweiIDCredential) => {
      showToast(`登录组件登录完成:${JSON.stringify(response)}`)
      Logger.WARN({
        msg: `登录组件登陆完成:${JSON.stringify(response)}`
      })
    })
  build() {
    Column() {
      LoginWithHuaweiIDButton({
        params: {
          style: loginComponentManager.Style.BUTTON_WHITE,
          loginType: loginComponentManager.LoginType.ID,
          borderRadius: 10
        },
        controller: this._loginController
      }).width("68%")
        .margin({
          top: 20
        })
        .height(50)
        .backgroundColor(Color.Red)

      Text("华为登录")
        .fontSize(15)
        .margin({
          top: 20
        })
        .padding({
          top: 10,
          bottom: 10
        })
        .textAlign(TextAlign.Center)
        .width("68%")
        .fontColor(Color.Black)
        .backgroundColor(Color.White)
        .borderRadius(10)
        .onClick(() => {
          //showToast("登录")
          try {
            const _apiLoginController: authentication.AuthenticationController =
              new authentication.AuthenticationController()
            const request = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest()
            // request.scopes = ['profile','openid']
            // request.permissions = ['idtoken']
            // request.forceAuthorization = true
            request.forceLogin = true
            request.state = util.generateRandomUUID()
            _apiLoginController.executeRequest(request, (error, data) => {
              if (error) {
                Logger.ERROR({
                  msg: `API登陆失败:${JSON.stringify(error)}`
                })
                showToast($r("app.string.login_error_formater", JSON.stringify(error)))
              } else {
                Logger.ERROR({
                  msg: `API登陆完成:${JSON.stringify(data)}`
                })
                let loginWithHuaweiIDResponse = data as authentication.LoginWithHuaweiIDResponse;
                showToast(`API登录完成:${JSON.stringify(loginWithHuaweiIDResponse)}`)
              }
            })
          } catch (e) {
            Logger.ERROR({
              msg: `API登陆异常:${JSON.stringify(e)}`
            })
            showToast($r("app.string.login_error_formater", JSON.stringify(e)))
          }
        })
    }
    .height('100%')
    .width('100%')
  }
}
阅读 406
logo
HarmonyOS
子站问答
访问
宣传栏