flutter_web_auth icon indicating copy to clipboard operation
flutter_web_auth copied to clipboard

Authenticaion seen as canceled when using the normal flow - Android

Open ElDuderini opened this issue 2 years ago • 2 comments

When the call back for authentication happens on android, the plugin sees it as the user canceling the login. Here is how I implement it: Screenshot 2022-08-04 at 16 40 45 Screenshot 2022-08-04 at 16 41 56 Here is the error: Screenshot 2022-08-04 at 16 42 49 I also tried setting the launch mode of the android app to a single instance since I thought that would fix the issue of the callback data not being retrieved properly, but it didn't work. iOS works as intended.

ElDuderini avatar Aug 04 '22 14:08 ElDuderini

@ElDuderini did you get anywhere with this issue? Running into the same problem.

paul-charlton avatar Sep 22 '22 13:09 paul-charlton

@ElDuderini did you get anywhere with this issue? Running into the same problem.

I ended up switching to a fork that is more actively developed (https://github.com/ThexXTURBOXx/flutter_web_auth_2) and I figured out the mistake I was making with this, though it still isn't behaving the way I wanted.

Basically, I set up the android manifest incorrectly, I needed to set up a separate activity solely for the behavior of the plugin. When this was implemented, this issue no longer showed up where the data was successfully being transferred back into the application. Though, now when I try to redirect back to the app, it just doesn't work. I have to press the back button in android to return to the app to have it updated with the new login information. Here is what I have my AndroidManifest activities set as.

<activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleInstance"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

        </activity>
    <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="appname" />
        </intent-filter>
    </activity>

ElDuderini avatar Sep 22 '22 14:09 ElDuderini

Basically, I set up the android manifest incorrectly, I needed to set up a separate activity solely for the behavior of the plugin. When this was implemented, this issue no longer showed up where the data was successfully being transferred back into the application.

We have added a troubleshooting section to the readme that hopefully should make this clearer!

https://github.com/LinusU/flutter_web_auth#troubleshooting 🎉

Let me know if you still need more help

LinusU avatar Nov 01 '22 08:11 LinusU