xamarin / Xamarin.Auth

Xamarin.Auth
Apache License 2.0
542 stars 350 forks source link

IntentFilter on Http/Https not working while page gets redirected #431

Open NickeManarin opened 4 years ago

NickeManarin commented 4 years ago

My IntentFilter on an Activity is not intercepting the URL when page is redirected/navigated, only when tab is open or when URL scheme changes.

Steps to Reproduce

  1. Create a Xamarin.Forms or Xamarin.Android project.
  2. Add the Xamarin.Auth nuget.
  3. Create company page and app in LinkedIn.
  4. Use this example to code all necessary steps in authorization via identity provider, just replacing with LinkedIn URLs.
  5. Add Redirect URL in LinkedIn app settings, it must be the same as the passed parameter in Xamarin.Auth. In my case, I've tried various URLs, even localhost without success. For the IntentFilter below, I'm using http://localhost:1445/callback.
  6. Add this Activity with the IntentFilter:
 [Activity(Label = "LinkedInInterceptorActivity", NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataSchemes = new[] { "http", "https" }, DataHosts = new []  { "localhost" }, DataPort = "1445", DataPathPrefix = "/callback")]
public class LinkedInInterceptorActivity : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        //Convert Android.Net.Url to Uri
        var uri = new Uri(Intent.Data.ToString());

        //Load redirectUrl page
        Global.Authenticator.OnPageLoading(uri);

        var intent = new Intent(this, typeof(MainActivity));
        intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
        StartActivity(intent);

        Finish();
    }
}
  1. Run the app.

Expected Behavior

After a successful authorization, the page redirects to the [Redirect URL]+ ?code=[AuthCode] and the IntentFilter should intercept the call.

App flow: User presses "Login with LinkedIn" ▶ App opens a "custom tab" browser (which uses the native UI of the browser, not a WebView inside the app) ▶ User logs in on LinkedIn ▶ User authorizes connection between my app and his profile ▶ LinkedIn.com redirects to another Http/Https URL, after checking if the URL is one of the authorized redirect URLs ▶ The browser tab gets closed as the IntentFilter was able to intercept the navigation (since there's a code that actively closes the browser).

Actual Behavior

After a successful authorization, the page redirects to the [Redirect URL]+ ?code=[AuthCode] but the IntentFilter does not intercept the call.

App flow: User presses "Login with LinkedIn" ▶ App opens a "custom tab" browser (which uses the native UI of the browser, not a WebView inside the app) ▶ User logs in on LinkedIn ▶ User authorizes connection between my app and his profile ▶ LinkedIn.com redirects to another Http/Https URL, after checking if the URL is one of the authorized redirect URLs ▶ The browser tab is still being displayed, the IntentFilter failed to intercept the navigation.

Version Information

Microsoft Visual Studio Community 2019 Version 16.4.3 VisualStudio.16.Release/16.4.3+29709.97 Microsoft .NET Framework Version 4.8.03752

Installed Version: Community

Visual C++ 2019 00435-60000-00000-AA924 Microsoft Visual C++ 2019

Xamarin 16.4.000.308 (d16-4@4755fb3) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 16.4.0.475 (remotes/origin/d16-4@ac250f5aa) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 10.1.3.7 (d16-4/d66aed0) Xamarin.Android Reference Assemblies and MSBuild support. Mono: fd9f379 Java.Interop: xamarin/java.interop/d16-4@c4e569f ProGuard: xamarin/proguard/master@905836d SQLite: xamarin/sqlite/3.28.0@46204c4 Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b

Xamarin.iOS and Xamarin.Mac SDK 13.10.0.17 (5f802ef) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

MattiaVicari commented 2 years ago

I'm facing with the same issue in my Xamarin App. I see that this issue is open since the 23rd January 2020. In the meantime, has someone found a workaround for this problem? Thank you

sviluppomania commented 2 years ago

@Redth @jonathanpeppers @NickeManarin

NickeManarin commented 2 years ago

No and I'm no longer working with that. It's possible to close this issue ticket.

GuiRoux5555 commented 2 years ago

Same issue for me

MattiaVicari commented 2 years ago

Workaround: use a custom schema different from http and https (for example oauth://) for the callback URL. In this way you can avoid the IntentFilter of the browser and you can intercept that by your App Activity.

Example for the activity:

[Activity(Label = "My Login Authenticator", NoHistory = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTop)] [IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataScheme = "oauth", DataHosts = new[] { "mydomain.com", "www.mydomain.com" }, DataPathPrefix = "/my_login_callback")]

I didn't find any other solution.