中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何取消应用已授权的华为账号?
微信扫码分享
import { authentication } from '@kit.AccountKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { util } from '@kit.ArkTS'; // 创建取消授权请求,并设置参数 let cancelRequest = new authentication.HuaweiIDProvider().createCancelAuthorizationRequest(); cancelRequest.state = util.generateRandomUUID(); @Entry @Component struct Index { build() { Column() { Button("取消授权").onClick(() => { // 执行请求 try { let controller = new authentication.AuthenticationController(getContext(this)); controller.executeRequest(cancelRequest, (err, data) => { if (err) { hilog.error(0x0000, 'testTag', 'cancel fail,error: %{public}s', JSON.stringify(err)); return; } let cancelAuthorizationResponse = data as authentication.CancelAuthorizationResponse; let state = cancelAuthorizationResponse.state; if (state != undefined && cancelRequest.state != state) { hilog.error(0x0000, 'testTag', 'cancel fail,The state is different: %{public}s', JSON.stringify(cancelAuthorizationResponse)); return; } hilog.info(0x0000, 'testTag', 'cancel success: %{public}s', JSON.stringify(cancelAuthorizationResponse)); }); } catch (error) { hilog.error(0x0000, 'testTag', 'cancel failed: %{public}s', JSON.stringify(error)); } }) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } }