#鸿蒙学习大百科#如何取消应用已授权的华为账号?

如何取消应用已授权的华为账号?

HarmonyOS
2024-10-23 09:46:29
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
莫名瞄一眼
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)
  }
}
分享
微博
QQ
微信
回复
2024-10-23 15:52:31
相关问题
#鸿蒙学习大百科#什么是应用沙箱?
294浏览 • 1回复 待解决