4

In flutter i am working with fitbit web api integration, in this process i need to authenticate the user from their web site after that i will get access_token in redirection url. So, i need to access that token and close that web page and redirect back to my application with the access token for further api call.

To achieve the above flow am using flutter_web_auth plugin

Here is my code: after clicking on a button am invokin the below method.

  void authenticate() async {
// Present the dialog to the user
print('Before Authentication');
final result = await FlutterWebAuth.authenticate(
  url: "https://www.fitbit.com/oauth2/authorize?response_type=token&client_id=22BZMN&expires_in=2592000&scope=activity%20nutrition%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight&redirect_uri=https://tekfriday.com", //TODO: add &prompt=login to shwo login screen every time.
  callbackUrlScheme: "tekfriday",
);
final token = Uri.parse(result).queryParameters['token'];
print('token');
print(token);

}

Here is my manifest file:

        <activity android:name="com.tekfriday.wear_poc.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="tekfriday" />
        </intent-filter>
    </activity>

The authentication flow is happening properly, But after authentication it is not redirecting back to my application. Is there any mistake in above code ?.

  • 1
    i'm having a similar problem. code execution never gets past `await FlutterWebAuth...` and the web view window just stays there with the main app in the background. as a point of comparison, i tried using the flutter web auth example app as the starting application, and then redirecting to my main app and that works! it's like the library isn't ready to return the app to the foreground when the auth flow is finished. i'm going to look into this more and will post an answer if i figure it out. i'm on iOS 14 – Eric S. Sep 30 '21 at 20:13
  • seems to be an open issue in`oauth2_client`, which uses `flutter_web_auth` under the hood. https://github.com/teranetsrl/oauth2_client/issues/83 – Eric S. Oct 04 '21 at 18:11

1 Answers1

0

Chance manifest
<data android:scheme="tekfriday"/> => <data android:scheme="com.tekfriday" android:host="login"/>
and
...?redirect_uri=https://tekfriday.com" => ...?redirect_uri=com.tekfriday://login"

Mochte
  • 1