const scripts = ['https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js']; const CLIENT_ID = 'wallet.cebggame.com'; const REDIRECT_URI = `${location.origin}${location.pathname}`; // Authorization scopes required by the API; multiple scopes can be included, separated by spaces. const SCOPES = 'name email'; export class AppleClient { initClient() { let state = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); let nonce = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); AppleID.auth.init({ clientId : CLIENT_ID, scope : SCOPES, redirectURI : REDIRECT_URI, state, nonce, usePopup : true }); } async initAppleClient() { await loadSingleScript([scripts[0]]); this.initClient(); } async login(funid) { let result = {}; try { const data = await AppleID.auth.signIn({state: funid+''}) // Handle successful response. console.log("apple login success: ", JSON.stringify(data)) result = { data: data.authorization.id_token, errcode: 0, }; } catch ( error ) { // Handle error. console.log('apple login error: ', JSON.stringify(error)) result = { errcode: 1, errmessage: error.error || error.message || error, } } jc.wallet.nativeSvr.handleNativeCallback(funid, JSON.stringify(result)); } }