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

OAuth2.0 Google not working #1790

Open
BogdanAlexandru11 opened this issue Sep 2, 2024 · 2 comments
Open

OAuth2.0 Google not working #1790

BogdanAlexandru11 opened this issue Sep 2, 2024 · 2 comments

Comments

@BogdanAlexandru11
Copy link

What happened?

Hi all,
I am working on a flutter app and I am trying to get the sign in with google functionality working, but It doesn't seem to work and I believe there might be a bug.

I have followed the instructions from the following pages:

This is the code I am using to attempt to sign in with google:

  Future<User> signInWithGoogle() async {
    logger.d('Attempting to sign in with Google');
    try {
      final googleSignIn = GoogleSignIn();
      final googleUser = await googleSignIn.signIn();

      if (googleUser == null) {
        throw Exception('Google sign-in aborted');
      }
      final googleAuthCodeCredentials = Credentials.googleAuthCode(googleUser.serverAuthCode!);
      final currentUser = await realmApp.logIn(googleAuthCodeCredentials);
      return currentUser;
    } catch (e) {
      logger.e('Failed to sign in with Google: $e');
      throw Exception('Failed to sign in with Google: $e');
    }
  }

The line containing final googleAuthCodeCredentials = Credentials.googleAuthCode(googleUser.serverAuthCode!); executes successfully and I can see the object being created, however when the realmApp attempts to logIn with those credentials a 401 is thrown and I can see the following in MongoDB console
image

I have attempted the following

  • validated the clientId and clientSecret match
  • triple checked the configuration and its all as required
  • made sure that Google is enabled as a provider in MongoDB Atlas
  • tried using with and without OpenId Connect
  • tried using various redirectUrl's such as http://localhost:8081 or something like https://<appname>.realm.mongodb.com/api/client/v2.0/auth/callback -> the latter one was suggested by cursorAI, was not able to find any other references in the documentation.

My MongoDB Atlas setup:
image

The Client ID I set up in Google Console:
image

Repro steps

  • Create clientId in Google Console
  • Enable Google Provider in MongoDB Atlas
  • Add the clientId + secret in MongoDB Atlas under Google OAuth2.0
  • Attempt to sign in using google

Version

Flutter 3.24.1, Dart 3.5.1

What Atlas Services are you using?

Atlas Device Sync

What type of application is this?

Flutter Application

Client OS and version

macOS 14.6.1

Code snippets

No response

Stacktrace of the exception/crash you're getting

`
Failed to sign in with Google: AppException: unauthorized, status code: 401, link to server logs: https://services.cloud.mongodb.com/groups/{uniqueUrl}
`

Relevant log output

No response

Copy link

sync-by-unito bot commented Sep 2, 2024

➤ PM Bot commented:

Jira ticket: RDART-1096

@Shreedhar73
Copy link

As of now, the device sync is deprecated, its better to look into other options.
https://www.mongodb.com/docs/atlas/device-sdks/deprecation/

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

No branches or pull requests

2 participants