Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck at authorisation screen @okrad #202

Open
avinashk369 opened this issue Oct 13, 2024 · 5 comments
Open

Stuck at authorisation screen @okrad #202

avinashk369 opened this issue Oct 13, 2024 · 5 comments

Comments

@avinashk369
Copy link

can you please share the fix for this. @okrad

At least I could open this as a popup, but nothing happens from there after authorize the redirect.

In the standard authorization flow, the authorization code is exchanged after the authorize button is pressed, but this does not occur and the popup is not closed in the first place, causing a redirect in the popup.

I was going to test on localhost, but am I doing something wrong?

スクリーンショット 2022-06-02 9 11 02

Originally posted by @myConsciousness in #131 (comment)

@avinashk369
Copy link
Author

authorisation using browser window works as expected but native twitter apps stuck at authorisation screen.

@Abhishek-Khanal
Copy link
Contributor

Use custom scheme instead of https

@avinashk369
Copy link
Author

avinashk369 commented Oct 21, 2024

Use custom scheme instead of https

Thanks, but i am already using custom scheme "appname://callback". Although it does work with browser but problem is with authorisation using twitter app.

<activity
            android:name="com.linusu.flutter_web_auth_2.CallbackActivity"
            android:exported="true"
            android:launchMode="singleTop">
            <intent-filter android:label="flutter_web_auth_2">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="appname" android:host="callback"/>
            </intent-filter>
        </activity>
       final result = OAuth2Helper(
        TwitterOAuth2Client(
          redirectUri: "appname://callback"
          customUriScheme: "appname",
        ),
        grantType: OAuth2Helper.authorizationCode,
        clientId: dotenv.env['TWITTER_AUTH_CLIENT_ID']!,
        clientSecret: dotenv.env['TWITTER_AUTH_CLIENT_SECRET']!,
        scopes: ['tweet.read tweet.write users.read offline.access'],
      );

      final token = await result.fetchToken();
      print('Token: ${token.accessToken}');
 

authorisation using twitter app generates the token but it doesn't return back to the app. in browser case it generates the token and return to the app.

BTW i have tried flutter_web_auth_2: ^4.0.1 and oauth2_client: ^3.3.0 packages.

@Abhishek-Khanal
Copy link
Contributor

Abhishek-Khanal commented Oct 21, 2024

This is what I am using and it's redirecting back to the app as expected.
`

        <intent-filter android:label="flutter_web_auth_2">
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:scheme="appname"
                android:host="callback" />
        </intent-filter>
    </activity>`
final twitterClient = TwitterOAuth2Client(
      redirectUri: 'appname://callback,
      customUriScheme: 'appname',
    );
    final oauth2Helper = OAuth2Helper(
      twitterClient,
      webAuthOpts: {
        'intentFlags': 1 << 29 | 1 << 28 | 1 << 30,
        'preferEphemeral': true,
      },
      authCodeParams: {'response_type': 'code'},
      clientId: '*************Your id**************************',
      accessTokenHeaders: {'Content-Type': 'application/x-www-form-urlencoded'},
      clientSecret: '***********Your secret******************',
      scopes: ['tweet.read', 'tweet.write', 'users.read', 'offline.access'],
    );

@ThexXTURBOXx
Copy link
Contributor

There is also a known problem with task affinities and launch modes (see #113). In order to ensure that flutter_web_auth_2 works correctly, set android:launchMode="singleTop" and remove any android:taskAffinity entries. This configuration is guaranteed to work.

Taken from https://pub.dev/packages/flutter_web_auth_2#troubleshooting-android

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants