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
53 stars 54 forks source link

Authenticate in multiple activities #38

Closed KoheiYamashita closed 1 year ago

KoheiYamashita commented 1 year ago

Describe the bug

Our app has two activities implemented: ActivityA and ActivityB. When executing the authenticate function in ActivityB, it redirects to ActivityA.

To Reproduce

Steps to reproduce the behavior:

  1. Launch the ActivityB.
  2. Execute the authenticate function.
  3. Observe the redirect to ActivityA.

Expected behavior

Redirect to the Activity that performed the authenticate.

Screenshots

Not applicable.

Device

Additional context

ActivityA has the following intent-filter:

<intent-filter>
  <action android:name="android.intent.action.MAIN"/>
  <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

This filter is used to launch the main screen of the app.

ActivityB is set up to receive text data with the following intent-filter:

<intent-filter>
  <action android:name="android.intent.action.SEND"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <data android:mimeType="text/plain"/>
</intent-filter>

CallbackActivity is defined as follows.

<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="com.example.oauth" android:host="callback" />
          </intent-filter>
</activity>

Checklist

ThexXTURBOXx commented 1 year ago

Thanks for reporting the bug, I will take a look at it soon

KoheiYamashita commented 1 year ago

Hello. I'm currently checking how to use it, and it seems that using ActivityAware allows you to obtain the associated Activity. https://api.flutter.dev/javadoc/io/flutter/embedding/engine/plugins/activity/ActivityAware.html I hope this helps with your analysis!

ThexXTURBOXx commented 1 year ago

Does the issue persist when you remove the DEFAULT category from the intent filter of ActivityB?

KoheiYamashita commented 1 year ago

Thank you for your suggestion. The android.intent.category.DEFAULT is necessary for receiving implicit Intent. I believe that if you do not set this, it will not be displayed on the shared screen.

https://developer.android.com/guide/topics/manifest/category-element

ThexXTURBOXx commented 1 year ago

In that case, I am unsure if I can fix this issue since flutter_web_auth_2 does not initiate a redirect to any activity as can be seen in these two files:

When initiating the authenticate, a custom tabs intent is being launched. When the callback URL scheme is detected, the callback activity will be called which then just finishes and leaves you with the original activity which had launched the authenticate process. There must be something wrong in your setup, I think (maybe ActivityB launches in the background for some reason?)

KoheiYamashita commented 1 year ago

Thank you very much. After trying various things like changing the launchMode, it seems that it was being redirected to the main task. I guess this is probably the standard behavior of the plugin. I will let you know if I find a workaround, but for now, I'm thinking of closing this issue. Is that okay?

ThexXTURBOXx commented 1 year ago

No problem! If you find some workaround, please let me know. Then I can extend the troubleshooting guide. Thank you very much!