中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何解析身份验证后的verifyToken?
微信扫码分享
import { buffer } from '@kit.ArkTS'; function decodeBase64(data: string):string { return buffer.from(data, 'base64').toString('utf8'); } function decodeIdToken(token: string):void { const parts = token.split('.'); if (parts.length !== 3) { console.error('format of idToken is inValid'); return; } let idTokenObj: Record<string, Object> = {}; idTokenObj['header'] = JSON.parse(decodeBase64(parts[0])); idTokenObj['payload'] = JSON.parse(decodeBase64(parts[1])); idTokenObj['signature'] = parts[2]; // 授权后的nonce可以从idTokenObj中解析出来 let payLoad: Record<string, string> = idTokenObj['payload'] as Record<string, string>; let data: string = payLoad['data']; let nonce: string = JSON.parse(data).nonce; // 开发者处理nonce }