ThexXTURBOXx / flutter_web_auth_2

Flutter plugin for authenticating a user with a web service
https://pub.dev/packages/flutter_web_auth_2
MIT License
51 stars 50 forks source link

Redirect URI results in DNS #27

Closed cavedweller closed 1 year ago

cavedweller commented 1 year ago

Issue

I am trying to authenticate a user with LinkedIn. I am able to get all the way to the authorize screen but when the user has successfully signed in the redirect URI tries to target a website instead of redirecting back into the app. The redirect URI is not a website so it just loads a DNS error on the web page.

How do I redirect back int the app?

Android Manifest

`<activity android:name="com.linusu.flutter_web_auth_2.CallbackActivity" android:exported="true">
            <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="social-login" android:host="callback" />
            </intent-filter>
</activity>

Dart code

var encoded = Uri.encodeComponent('https://social-login/callback');
final url = Uri.parse("https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=*********&redirect_uri=$encoded&scope=w_member_social");
        try {
          final result =
              await FlutterWebAuth2.authenticate(url: url.toString(), callbackUrlScheme: 'social-login');
          print('successs');
          print(result);
        } on PlatformException catch (e) {
          print('error');
          print(e.message);
          print(e.details);
        }

Call back URL as per Linkedin

image

Device used

Samsung s10

Additionally

I am also trying to log into TikTok and I am facing the same issue where it tries redirecting to the URI instead of the back to the app

Any help would be greatly appreciated 😎

ThexXTURBOXx commented 1 year ago

You did not follow the Readme correctly. Your callback URLs all start with https. Thus, https is your URL scheme. If you are able to change this to something else, you should definetly do that since http and https could interfere with other apps on the device.

cavedweller commented 1 year ago

@ThexXTURBOXx Thank you for your response. So I have changed the callback scheme but the issue persists.

Dart Code

 var encoded = Uri.encodeComponent('https://social-login');
        final url = Uri.parse(
            'https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=78bo09ary48lus&redirect_uri=$encoded&scope=w_member_social');
        try {
          final result =
              await FlutterWebAuth2.authenticate(url: url.toString(), callbackUrlScheme: 'https'); //social-login

          print('success');
          print(result);
        } on PlatformException catch (e) {
          print('error');
          print(e.message);
          print(e.details);
        }

Android Manifest

<activity android:name="com.linusu.flutter_web_auth_2.CallbackActivity" android:exported="true">
            <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= "https"/>
                <!--<data android:scheme="social-login" android:host="callback" />-->
            </intent-filter>
        </activity>

https://user-images.githubusercontent.com/70595829/205957620-3c1cf3cf-b7f8-4098-827a-3f987b046c76.mp4

Call back URLs

image

ThexXTURBOXx commented 1 year ago

Please only authorize the following redirect URL for your app: https://social-login/callback

Also, again, it is very advisable not to use https!

Finally, please also try the following fragment in AndroidManifest.xml:

<activity android:name="com.linusu.flutter_web_auth_2.CallbackActivity" android:exported="true">
            <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= "https" android:host="social-login" android:pathPrefix="/callback"/>
            </intent-filter>
        </activity>

and if that one also does not work, try this one:

<activity android:name="com.linusu.flutter_web_auth_2.CallbackActivity" android:exported="true">
            <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= "https" android:host="social-login" android:pathPrefix="callback"/>
            </intent-filter>
        </activity>
cavedweller commented 1 year ago

@ThexXTURBOXx Thanks again but I am still facing the same issue

Only one redirect URL

image

Unfortunately I have to use either the https or http path image

<activity android:name="com.linusu.flutter_web_auth_2.CallbackActivity" android:exported="true">
            <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= "https" android:host="social-login" android:pathPrefix="/callback"/>-->
                <data android:scheme= "https" android:host="social-login" android:pathPrefix="callback"/>
            </intent-filter>
        </activity>

I did try both but they do not work

 var encoded = Uri.encodeComponent('https://social-login/callback');
        final url = Uri.parse(
            'https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=78bo09ary48lus&redirect_uri=$encoded&scope=w_member_social');
          final result =
              await FlutterWebAuth2.authenticate(url: url.toString(), callbackUrlScheme: 'https'); //social-login
ThexXTURBOXx commented 1 year ago

In that case, sadly, this seems to be one of these cases where the callback provider (LinkedIn) is at fault. There is nothing application/library developers can do about such cases until they fix their backend. You could try getting in contact with them to allow custom callback URL schemes

justsaagar commented 1 year ago

Hi, I am facing issue with the instagram login. Same issue.

        <activity android:name="com.linusu.flutter_web_auth_2.CallbackActivity" android:exported="true">
            <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= "https" android:host="social-login" android:pathPrefix="/callback"/>
            </intent-filter>
        </activity>

Code file :

    final authUrl =
        'https://www.instagram.com/oauth/authorize?client_id=$_instagramClientId&redirect_uri=$encoded&scope=user_profile,user_media&response_type=code';

    final result = await FlutterWebAuth2.authenticate(
      url: authUrl,
      callbackUrlScheme: 'https',
    );
SankethBK commented 11 months ago

Facing same issue with Dropbox Oauth

alexandra-flaminjoy commented 6 months ago

@justsaagar hey, did you manage to implement it?