Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const loginGoogle = () => {
- return new Promise(async (resolve, reject) => {
- const user = await GoogleSignin.signIn().catch(error => {
- // console.log('WRONG SIGNIN', error);
- console.log('getOpenIdToken',getOpenIdToken);
- Alert.alert("13");
- });
- if (user) {
- const credential = await googleGetCredential();
- if (credential) {
- const result = await getOpenIdToken('accounts.google.com',
- credential.identityId, credential.idToken);
- resolve(result);
- Alert.alert("8");
- return;
- }
- reject('Authentication failed');
- console.log('failed');
- Alert.alert("9");
- return;
- }
- return;
- });
- };
- export const getOpenIdToken = async (provider, identityId, token) => {
- const payload = {
- IdentityId: identityId,
- Logins: {
- [provider]: token,
- },
- };
- Alert.alert("10");
- try {
- const rsp = await fetch(COGNITO_IDENTITY_API, {
- method: 'POST',
- headers: new Headers({
- 'X-Amz-Target': 'AWSCognitoIdentityService.GetOpenIdToken',
- 'Content-Type': 'application/x-amz-json-1.1',
- random: new Date().valueOf(),
- 'cache-control': 'no-cache',
- }),
- body: JSON.stringify(payload),
- });
- if (!rsp.ok) {
- logout();
- } else {
- const json = await rsp.json();
- return json.Token;
- }
- } catch (e) {
- console.log('Error of getOpenIdToken: ', e);
- }
- };
- const googleConfigure = () => {
- GoogleSignin.hasPlayServices({ autoResolve: true })
- .then(() =>
- GoogleSignin.configure({
- iosClientId: GOOGLE_SIGNIN_IOS_CLIENT_ID,
- webClientId: GOOGLE_SIGNIN_WEBCLIENT_ID,
- })
- );
- };
- export const init = () => {
- googleConfigure();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement