Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google login web not returning any data. #46

Open
Saqib92 opened this issue Nov 1, 2024 · 45 comments
Open

Google login web not returning any data. #46

Saqib92 opened this issue Nov 1, 2024 · 45 comments

Comments

@Saqib92
Copy link

Saqib92 commented Nov 1, 2024

Google Login not working in browser. it open google login window and after authorizing it closes but data is not returning.

@MalikHamza007
Copy link

Google Login not working in browser. it open google login window and after authorizing it closes but data is not returning.

Same issue with me :(

@WcaleNieWolny
Copy link
Contributor

There is an open PR addressing this issue: #37

@Saqib92
Copy link
Author

Saqib92 commented Nov 6, 2024

Not working on web.
Throwing this error on web. Before that at least Google Auth window were opening.

Screenshot 2024-11-06 at 1 00 47 PM

@Saqib92 Saqib92 mentioned this issue Nov 6, 2024
1 task
@WcaleNieWolny
Copy link
Contributor

This does not look like a problem with the plugin. The stacktrace does not mention CapacitorSociaLogin once

@MalikHamza007
Copy link

Not working on web. Throwing this error on web. Before that at least Google Auth window were opening.

Screenshot 2024-11-06 at 1 00 47 PM

Hey @Saqib92 this is my mail
@[email protected]

can you send me the sample code

@Saqib92
Copy link
Author

Saqib92 commented Nov 6, 2024

Not working on web. Throwing this error on web. Before that at least Google Auth window were opening.
Screenshot 2024-11-06 at 1 00 47 PM

Hey @Saqib92 this is my mail @[email protected]

can you send me the sample code

what issue are you facing. your image is broken.

@Saqib92
Copy link
Author

Saqib92 commented Nov 6, 2024

This does not look like a problem with the plugin. The stacktrace does not mention CapacitorSociaLogin once

my implementation:

async googleLogin() {
    let options: InitializeOptions = {};
    if (Capacitor.getPlatform() == 'ios') {
      options = {
        google: {
          iOSClientId: environment.google.iOSClientId, // the iOS client id
          iOSServerClientId: environment.google.iOSServerClientId // the iOS server client id (optional)
        },
      }
    } else {
      console.log('here')
      options = {
        google: {
          webClientId: environment.google.webClientId // the web client id for Android and Web
        }
      }
    }
    await SocialLogin.initialize(options);

    const res = await SocialLogin.login({
      provider: 'google',
      options: {
        scopes: ['email', 'profile'],
      },
    });
    console.log(res);
  }

@luckashenri
Copy link

Same here, no response after login at all.
I'm trying google login

@riderx
Copy link
Contributor

riderx commented Nov 6, 2024

I'm looking with @Saqib92 to find a fix

@Saqib92
Copy link
Author

Saqib92 commented Nov 6, 2024

Demo Repo to reproduce issue:
https://github.com/Saqib92/Saqib92-camera-preview-uploader-issue

@WcaleNieWolny
Copy link
Contributor

WcaleNieWolny commented Nov 7, 2024

@Saqib92 you want to remove scopes when calling login
Right now, you are doing

    const res = await SocialLogin.login({
      provider: 'google',
      options: {
        scopes: ['email', 'profile'], // <--- this is bad
      },
    });

I did not implement scopes yet. It's something that could be implemented in the near future, but for the time being if you set scopes the code will reject your login

@WcaleNieWolny
Copy link
Contributor

The correct way would be:

    const res = await SocialLogin.login({
      provider: 'google',
      options: {},
    });

This works better, but you get this error

image

Please make sure you don't have any redirect URLs added in the Google Console. This is clearly mentioned in the documentation
image

@Saqib92
Copy link
Author

Saqib92 commented Nov 7, 2024

The correct way would be:

    const res = await SocialLogin.login({
      provider: 'google',
      options: {},
    });

This works better, but you get this error

image

Please make sure you don't have any redirect URLs added in the Google Console. This is clearly mentioned in the documentation image

Thank you, But i do require scopes as my app targets some sensitive scopes, like spreadsheet read and write permission via serverAuthCode and refresh token.

@WcaleNieWolny
Copy link
Contributor

I could implement additional scopes, but first please make sure that your app works with the current version of the plugin.

Please let me know if removing scopes fixed your problem

@Saqib92
Copy link
Author

Saqib92 commented Nov 7, 2024

I could implement additional scopes, but first please make sure that your app works with the current version of the plugin.

Please let me know if removing scopes fixed your problem

Yes, i can confirm it is working on Web WITHOUT scopes.

@MalikHamza007
Copy link

Hey @Saqib92
can i get your linkedin by any chance

@cihakmar
Copy link

cihakmar commented Nov 8, 2024

Hi,

I just build my app for production and tried google login on android device. After click on google login button the alert to select account is presented. After selecting account alert is closed but I have an error in sentry Google Sign-In failed: activity is cancelled by the user.. Could plese help?

EDIT: On debug version, it works like a charm.

Thanks

@WcaleNieWolny
Copy link
Contributor

What version are you on, and have you followed the setup guide?

@cihakmar
Copy link

cihakmar commented Nov 8, 2024

Sure, by the setup guide I have this function:

    let options: InitializeOptions = {};
    if (Capacitor.getPlatform() === 'ios') {
      options = {
        google: {
          iOSClientId: environment.googleIosClientId
        },
      }
    } else {
      options = {
        google: {
          webClientId: environment.googleWebClientId 
        }
      }
    }
    await SocialLogin.initialize(options);
    await this.loadingHelper.presentLoader(null, null, 'googleLoginApi()');

    try {
      const googleInit = await SocialLogin.initialize(options);
      Sentry.captureMessage('GOOGLE init resp: ' + JSON.stringify(googleInit));
      await this.loadingHelper.presentLoader(null, null, 'googleLoginApi()');
      const res = await SocialLogin.login({
        provider: 'google',
        options: {
          scopes: ['email', 'profile'],
        },
      });
      Sentry.captureMessage('GOOGLE login resp: ' + JSON.stringify(res));

      if (res && res.result.accessToken.token) {
        const profile = {
          token: res.result.accessToken.token,
          email: res.result.profile.email,
          // @ts-ignore
          fullName: res.result.profile.name
        };
        return profile;
      }
    } catch (e) {
      console.warn("GOOGLE LOGIN ERROR", e)
      Sentry.captureException('Error logging into GOOGLE: ' + JSON.stringify(e));
    }
  }

Version of @capgo/capacitor-social-login is 0.0.67.
Other versions:

Ionic:

   Ionic CLI                     : 6.20.9 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : not installed
   @angular-devkit/build-angular : 18.2.11
   @angular-devkit/schematics    : 18.2.11
   @angular/cli                  : 18.2.11
   @ionic/angular-toolkit        : 11.0.1

Capacitor:

   Capacitor CLI      : 6.1.2
   @capacitor/android : 6.1.2
   @capacitor/core    : 6.1.2
   @capacitor/ios     : 6.1.2

Utility:

   cordova-res : not installed globally
   native-run  : 2.0.1

System:

   NodeJS : v20.14.0 (/Users/mc/.nvm/versions/node/v20.14.0/bin/node)
   npm    : 10.7.0
   OS     : macOS Unknown

@Saqib92
Copy link
Author

Saqib92 commented Nov 8, 2024

Hey @Saqib92 can i get your linkedin by any chance

Please Email me at: [email protected]

@WcaleNieWolny
Copy link
Contributor

Can you try the "0.0.68-alpha.2" and follow the guide?

@MalikHamza007
Copy link

Hey @Saqib92 I am getting this error on ios anyone please help me i have a strict dead line

Screenshot 2024-11-09 at 1 29 41 PM

@WcaleNieWolny
Copy link
Contributor

@MalikHamza007 This is not an issues with the capacitor social login. As you can see, the capacitor social login plugin is using the latest UserDefaults (8.0) while the CapacitorMLKit/BarcodeScanning is using the older version (7.0).

Please contact the owner of CapacitorMLKit/BarcodeScanning and ask them to update their dependencies

@WcaleNieWolny
Copy link
Contributor

@Saqib92

Thank you, But i do require scopes as my app targets some sensitive scopes, like spreadsheet read and write permission via serverAuthCode and refresh token.

@riderx has requested that I implement serverAuthCode and custom scopes for this plugin. You can expect those features to be pushed before on Monday

@cihakmar
Copy link

Can you try the "0.0.68-alpha.2" and follow the guide?

Thank you, It looks working like a charm :-)

@Saqib92
Copy link
Author

Saqib92 commented Nov 12, 2024

@Saqib92

Thank you, But i do require scopes as my app targets some sensitive scopes, like spreadsheet read and write permission via serverAuthCode and refresh token.

@riderx has requested that I implement serverAuthCode and custom scopes for this plugin. You can expect those features to be pushed before on Monday

Is this done? I need SCOPES..

@WcaleNieWolny
Copy link
Contributor

Yes it is, try the 0.0.68-alpha.7 on NPM

@Saqib92
Copy link
Author

Saqib92 commented Nov 12, 2024

Yes it is, try the 0.0.68-alpha.7 on NPM

Its working with scopes,
But throwing error when adding grantOfflineAccess: true, in login options.

offlineAccess was working in 0.0.68-alpha.2 but returns null on serverAuthCode:
serverAuthCode : null

But throwing error in .7 version:
Screenshot 2024-11-12 at 3 25 04 PM

@WcaleNieWolny
Copy link
Contributor

Please read the docs.
The correct way to use "mode: 'offline'"

@WcaleNieWolny
Copy link
Contributor

Here are the docs for offline access

@Saqib92
Copy link
Author

Saqib92 commented Nov 12, 2024

Here are the docs for offline access

mode: 'offline' worked.

@playaz87
Copy link

I'm still not getting any response on web even with version 0.0.68

@WcaleNieWolny
Copy link
Contributor

WcaleNieWolny commented Nov 14, 2024

@playaz87 Yes, that is a known bug. Please use the development version which currently is 0.0.68-alpha.7.

@riderx has not yet had time to review #57 thus, all the fixes, changes to google are not implemented on main

@WcaleNieWolny
Copy link
Contributor

WcaleNieWolny commented Nov 14, 2024

Also, if you do use the development version please follow the docs

@WilliamFischer
Copy link

WilliamFischer commented Nov 14, 2024

v.0.0.68-alpha.7 returns data on browser after sign in, however

On v.0.0.68-alpha.7 i see the following error passing my credential to Firebase. I think the accessToken?.token is not what Google is expecting ;

**FirebaseError: Firebase: Unable to parse Google id_token: XYZ (auth/invalid-credential).**

Here is my implementation;

  import { Firestore } from '@angular/fire/firestore';
  import { GoogleLoginOnlineResponse, SocialLogin } from '@capgo/capacitor-social-login';
  import { GoogleAuthProvider, signInWithCredential } from '@angular/fire/auth';

  constructor(private firestore: Firestore) {
    SocialLogin.initialize({
      google: {
        webClientId:
          'XYZ',
        iOSClientId:
          'XYZ',
      },
    });
  }
async googleLogin() {
    const res = await SocialLogin.login({
      provider: 'google',
      options: {},
    });

    const googleResult = res.result as GoogleLoginOnlineResponse;
    const credential = GoogleAuthProvider.credential(
      googleResult.accessToken?.token
    );

    const result = await signInWithCredential(this.auth, credential);
    const user = result.user;
  }

@WcaleNieWolny
Copy link
Contributor

Is there a way to pass access_token or server_auth_code to firebase? id_token is not returned because it's simply impossible to get in the web version of this plugin.

@WilliamFischer
Copy link

WilliamFischer commented Nov 14, 2024

Yes my google auth on browser was working well with this plugin before i ran upgrades this morning :p

Firebase has a signInWithCredential method which is essentially expecting the access token, but its not happy with what its receiving now.

I have suspicions its related to this change completion(.success(user.accessToken.tokenString)) .... i wonder; why just give us the tokenString rather than the full accessToken object 🤔

@playaz87
Copy link

@WcaleNieWolny thanks, the alpha version is working

@Saqib92
Copy link
Author

Saqib92 commented Nov 14, 2024

@playaz87 Yes, that is a known bug. Please use the development version which currently is 0.0.68-alpha.7.

@riderx has not yet had time to review #57 thus, all the fixes, changes to google are not implemented on main

@riderx please review and merge, so we can go into production.

@WcaleNieWolny
Copy link
Contributor

Yes my google auth on browser was working well with this plugin before i ran upgrades this morning :p

Firebase has a signInWithCredential method which is essentially expecting the access token, but its not happy with what its receiving now.

I have suspicions its related to this change completion(.success(user.accessToken.tokenString)) .... i wonder; why just give us the tokenString rather than the full accessToken object 🤔

Yes, the development version is unfortunately a breaking change. As for firebase, can you attempt to use
"const credential = firebase.auth.GoogleAuthProvider.credential(null, accessToken);" as suggested by chatGPT

@WcaleNieWolny
Copy link
Contributor

You may also be able to use serverAuthCode with a custom edge function to return the refresh token and access token back to the client. This is referred as "offline mode" in the docs

@WilliamFischer
Copy link

WilliamFischer commented Nov 14, 2024

@WcaleNieWolny TYSM! Solved this by adding null as the first parameter to credential!

const googleResult = res.result as GoogleLoginOnlineResponse;
const credential = GoogleAuthProvider.credential(
  null, googleResult.accessToken?.token
);

const result = await signInWithCredential(this.auth, credential);
const user = result.user;
image

@cihakmar
Copy link

cihakmar commented Jan 6, 2025

Hi again,

on version 0.0.87 google login on web to not return accessToken. Other data are fine...

Response from Google login:
{ "provider": "google", "result": { "accessToken": null, "responseType": "online", "idToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6....", "profile": { "email": "xxx", "familyName": "xxx", "givenName": "xxx", "id": "xxx", "name": "xxx", "imageUrl": "xxx" } } }

@riderx
Copy link
Contributor

riderx commented Jan 21, 2025

@WcaleNieWolny

@WcaleNieWolny
Copy link
Contributor

on version 0.0.87 google login on web to not return accessToken. Other data are fine...

#112
@riderx can you merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants