中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
取消Account Kit 获取用户头像昵称授权
微信扫码分享
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}`); } }