realm / realm-dart

Realm is a mobile database: a replacement for SQLite & ORMs.
Apache License 2.0
768 stars 87 forks source link

OAuth2.0 Google not working #1790

Open BogdanAlexandru11 opened 2 months ago

BogdanAlexandru11 commented 2 months ago

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

My MongoDB Atlas setup: image

The Client ID I set up in Google Console: image

Repro steps

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

sync-by-unito[bot] commented 2 months ago

➤ PM Bot commented:

Jira ticket: RDART-1096

Shreedhar73 commented 2 months ago

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