flutter_web_auth icon indicating copy to clipboard operation
flutter_web_auth copied to clipboard

OAuth2 redirect issues

Open noe-gif opened this issue 4 years ago • 5 comments

Hello, I've read previous issues similar as mine but I still can't manage to make it work with all this information

So, as I understood your scheme needs to be structured as following : domain.company.name and the idea would be that your url is just your scheme + ://

(Just to clarify, I'm trying to use Reddit's Oauth, with reddit you need to create a dev app and get your clientID and secrets (https://www.reddit.com/prefs/apps))

The thing is I can't just put domain.company.name:// as url in here :

image

So what I did previously was putting http://127.0.0.1:65010/authorize_callaback and http as scheme.

My issue is that when I click on accept to authorize with OAuth2 it gets me here when it's supposed to go back on the app :

image

Even tho I get my token in the url : http://127.0.0.1:65010/authorize_callback?state=random_string&code=2stEhVnH294rcna_DqnRGKRv3w1lw#

I'm really stuck here so if anyone can help me that would be great, here is my code :

main.dart :

  final url = Uri.https('www.reddit.com', '/api/v1/authorize.compact', {
    'client_id': googleClientId,
    'response_type': 'code',
    'state': '$randomString',
    'redirect_uri': 'http://127.0.0.1:65010/authorize_callback',
    'duration': '$timeVariable',
    'scope': '$scopeList',
  });
  final result = await FlutterWebAuth.authenticate(
      url: url.toString(), callbackUrlScheme: "http", preferEphemeral: true);

AndroidManifest.xml :

(I didn't put this inside the .MainActivity)

	<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="http"
              		  android:host="authorize_callback"
              		  android:pathPrefix="/authorize_callback" />
            </intent-filter>
        </activity>

Thanks

noe-gif avatar Oct 10 '21 17:10 noe-gif

Stuck on the same problem here. Would like to note that this also occurs for https callback urls

Yodart avatar Oct 24 '21 04:10 Yodart

Stuck on the same problem here. Would like to note that this also occurs for https callback urls

I fixed the problem for basically no reason ^^ I changed redirect url to : domein.society.name://http://127.0.0.1:65010/authorize_callback

And it basically works so there you go

noe-gif avatar Oct 24 '21 08:10 noe-gif

Hey, @noe-gif Thanks for your response. That isn't really a fix tho, you're just using a custom URL scheme now. After further investigating I found that ASWebAuthenticationSession only uses custom callback URL schemes, to use http/https schemes the library would have to implement a solution using WKWebview (which is what the flutter_webview library uses)

Yodart avatar Oct 24 '21 16:10 Yodart

Stuck on the same problem here. Would like to note that this also occurs for https callback urls

I fixed the problem for basically no reason ^^ I changed redirect url to : domein.society.name://http://127.0.0.1:65010/authorize_callback

And it basically works so there you go

Can you please share your manifest and redirct uri and callback uri...... I am also stuck in this

rachittiwari8562 avatar Feb 10 '22 04:02 rachittiwari8562