add login with apple js
This commit is contained in:
parent
3e0111f5e8
commit
402fb24c30
45
assets/scripts/libs/apple.client.js
Normal file
45
assets/scripts/libs/apple.client.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
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.href;
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,9 +11,11 @@ import init, {
|
|||||||
} from '../../wasm/rustwallet.js';
|
} from '../../wasm/rustwallet.js';
|
||||||
import { QrScanner, showQr } from './qr_reading.js';
|
import { QrScanner, showQr } from './qr_reading.js';
|
||||||
import { GoogleClient } from './google.client.js';
|
import { GoogleClient } from './google.client.js';
|
||||||
|
import { AppleClient } from './apple.client.js';
|
||||||
// call native method
|
// call native method
|
||||||
|
|
||||||
let googleClient = null;
|
let googleClient = null;
|
||||||
|
let appleClient = null;
|
||||||
let walletCache = [];
|
let walletCache = [];
|
||||||
|
|
||||||
async function initWasm() {
|
async function initWasm() {
|
||||||
@ -21,6 +23,8 @@ async function initWasm() {
|
|||||||
googleClient = new GoogleClient();
|
googleClient = new GoogleClient();
|
||||||
await init();
|
await init();
|
||||||
await googleClient.initGoolgeClient();
|
await googleClient.initGoolgeClient();
|
||||||
|
appleClient = new AppleClient();
|
||||||
|
await appleClient.initAppleClient();
|
||||||
window.dispatchEvent(new CustomEvent('envready'));
|
window.dispatchEvent(new CustomEvent('envready'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +65,8 @@ window.jsb = {
|
|||||||
},
|
},
|
||||||
// BEGIN:: only for web
|
// BEGIN:: only for web
|
||||||
signWithApple: function (funid) {
|
signWithApple: function (funid) {
|
||||||
callNative({ action: 'signWithApple', funid });
|
//callNative({ action: 'signWithApple', funid });
|
||||||
|
appleClient.login(funid);
|
||||||
},
|
},
|
||||||
signWithGoogle: function (funid) {
|
signWithGoogle: function (funid) {
|
||||||
googleClient.login(funid);
|
googleClient.login(funid);
|
||||||
|
@ -3,10 +3,10 @@ const pages = {
|
|||||||
closePage: async function () {
|
closePage: async function () {
|
||||||
callNative({ action: 'closepage' });
|
callNative({ action: 'closepage' });
|
||||||
},
|
},
|
||||||
//loginWithApple: async function () {
|
loginWithApple: async function () {
|
||||||
// let res = await callMethod('walletLogin', '1', 'dev');
|
let res = await callMethod('walletLogin', '1', 'dev');
|
||||||
// console.log(res);
|
console.log(res);
|
||||||
//},
|
},
|
||||||
loginWithGoogle: async function () {
|
loginWithGoogle: async function () {
|
||||||
let res = await callMethod('walletLogin', '0', 'dev');
|
let res = await callMethod('walletLogin', '0', 'dev');
|
||||||
console.log(res);
|
console.log(res);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user