取消Account Kit 获取用户头像昵称授权

取消Account Kit 获取用户头像昵称授权

HarmonyOS
2024-08-07 08:42:49
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
易安安安
private cancelAuthorizationWithCallBack(): void {
    // 创建取消授权请求,并设置参数
    let cancelRequest: authentication.CancelAuthorizationRequest = new authentication.HuaweiIDProvider().createCancelAuthorizationRequest();
    // 用于防跨站点请求伪造,推荐采用如下方式给state赋值
    cancelRequest.state = util.generateRandomUUID();

    // 执行请求
    try {
      let controller: authentication.AuthenticationController = new authentication.AuthenticationController();
      controller.executeRequest(cancelRequest).then((data: authentication.AuthenticationResponse) => {
        let cancelAuthorizationResponse = data as authentication.CancelAuthorizationResponse;

        let state: string = cancelAuthorizationResponse.state!;
        if (cancelRequest.state != state) {
          hilog.error(0x0000, 'testTag', 'Failed to cancel. The state is different');
          this.result = 'cancel false: The state is different.';
          return;
        }
        this.result = 'data:' + JSON.stringify(cancelAuthorizationResponse);
      }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', `Failed to cancel. BusinessError Code: ${err.code}, message: ${err.message}`);
      })
    } catch (error) {
      hilog.error(0x0000, 'testTag', `Failed to cancel. Code: ${error.code}, message: ${error.message}`);
    }
  }
分享
微博
QQ
微信
回复
2024-08-07 10:54:27
相关问题
使用Account Kit 获取用户头像昵称
254浏览 • 1回复 待解决
HarmonyOS如何获取用户相册所有目录?
1915浏览 • 1回复 待解决
定位授权 直接提示用户拒绝授权
210浏览 • 1回复 待解决
求大佬告知如何向用户申请授权
388浏览 • 2回复 待解决
如何实现向用户申请授权的功能
1731浏览 • 1回复 待解决
如何向用户请求授权广告跟踪权限
225浏览 • 1回复 待解决