kfiross / flutter_mongodb_realm

Unofficial Flutter plugin for using MongoDB Realm services on Android, iOS and web.
Apache License 2.0
41 stars 17 forks source link

How to setup Google Auth correctly #42

Open LeonManolo opened 2 years ago

LeonManolo commented 2 years ago

Sorry to bother you again but I spent hours trying to setup Google Auth with this plugin. Im using the ^2.0.0-nullsafety.2 null safe version with google_sign_in: ^5.2.1. . I switched between enabling openid and not(excluded it from the scopes also). serverClientId is the clientId from Google Cloud after creating a Web App(I also created a android/ios App inside Google Cloud Console). Screenshot 2022-03-17 at 12 59 50

MongoDb Provider Setup: Screenshot 2022-03-17 at 13 01 49 Filled that with The Web Application Client Id and Secret etc.

dart code:

RealmApp.init("...");
// ...
Future<void> authenticate() async {
  final RealmApp app = RealmApp();

  final scopes = ['openid','profile', 'email']; // tried without openid also
  //const clientId = "normallyHereWouldBeMyId.apps.googleusercontent.com"; 
  const web = "normallyHereWouldBeMyId"; // Web Application Client Id
  final mongoUser = await app.login(
      Credentials.google(
        serverClientId: web, // just the start from "<ID>.apps.googleusercontent.com"
        scopes: scopes,
      ));

  print("EMAIL: ${mongoUser?.profile?.email}");

}

I added a console log to your plugin to get some error codes and recieved those messages (after the google sign in pop gets closed) When openId is enabled:

AUTH_ERROR(realm::app::ServiceError:47): token contains an invalid number of segments

When openId is disabled:

error fetching info from OAuth2 provider

It could be related to this issue but Im not sure: https://github.com/realm/realm-java/issues/7578

Do you maybe have any idea to help me here, thanks

kfiross commented 2 years ago

I still have to investigate this issue