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
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:
The Client ID I set up in Google Console:
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}
`
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:
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 consoleI have attempted the following
http://localhost:8081
or something likehttps://<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:
The Client ID I set up in Google Console:
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
Relevant log output
No response