Flutter-OAuth2 issue with redirecting back to app

Viewed 265

I want to set up the OAuth2 authentication using Google in my Flutter app. I chose the flutter_web_auth package. So far, I have managed that the user can log in to Google. After authentication, the user should be redirected back to my app. That does not work. After authentication, it always redirects the user to another URL(which I was given in the google console redirect URL) in the browser and not back to the app. How do I close the WebView after the user logs in and redirect the user to my app?

void googleSign() async {
final result = await FlutterWebAuth.authenticate(
    url:
        "https://sl-cinema.herokuapp.com/oauth2/authorize/google?redirect_uri=https://sl-cinema.herokuapp.com/oauth2/callback/google",
    callbackUrlScheme: "my.app");
//print(result);
final token = Uri.parse(result).queryParameters['token'];
print(token);

}

<activity android:name="com.linusu.flutter_web_auth.CallbackActivity" >
       <intent-filter android:label="flutter_web_auth">
           <action android:name="android.intent.action.VIEW" />
           <category android:name="android.intent.category.DEFAULT" />
           <category android:name="android.intent.category.BROWSABLE" />
           <data android:scheme="my.app" />
       </intent-filter>
   </activity>
1 Answers

It's better to use firebase_auth package, you can stay in the app without any redirections

Related