xamarin-docs
xamarin-docs copied to clipboard
I am struggling trying to define IntentFilters compatible with AndroidAppLinks
I think that what's needed must be just a small tweak, but am stuck - when I define my intent filter as shown above, it does work. I am passing new Uri("mydomain://mydatapath") as the callback url. However, in the document cited regarding AndroidAppLinks, it says that the data scheme for the intent filter has to be http or https. I figured that meant that I needed to change my IntentFilter attribute to set DataHost= my domain, DataScheme = http and AutoVerify = true on the IntentFilter attribute. I am able to define the IntentFilter that way, but when I call WebAuthenticator.AuthenticateAsync passing new Uri("http://mydomain://mydatapath"), then I get the error message "System.InvalidOperationException: 'You must subclass the WebAuthenticatorCallbackActivity and create an IntentFilter for it which matches your callbackUrl.'". How can I declare an intent filter that is compatible with AppLinks and use that in the AuthenticateAsync method parameters?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 1231a1e1-3734-9021-2cc7-eaf99478afca
- Version Independent ID: 01e5fdbe-0b15-4dbe-f8a0-ed40f8593302
- Content: Xamarin.Essentials: Web Authenticator - Xamarin
- Content Source: docs/essentials/web-authenticator.md
- Product: xamarin
- Technology: xamarin-essentials
- GitHub Login: @Redth
- Microsoft Alias: jodick
The intent filters should be specified such as
https://github.com/jamesmontemagno/app-monkeys/blob/master/MonkeysApp/Activities/MainActivity.cs#L19-L52
DataScheme == http and http and then the DataHost is your main site with and without www.
Thank you for the reply. Unfortunately, this is still not working for me. Your project shows only the intent filter, not the WebAuthenticator.AuthenticateAsync call, so possibly it's the URI I'm passing there that's the issue?
With this intent filter on my callback activity, the WebAuthenticator.AuthenticateAsync call works, but this intent filter is incompatible with AppLinks due to the lack of http/https data scheme: [Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop)] [IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataScheme = "com.mycompanyname.myappname", DataPath = "/myoauth2redirect")]
The (successful) call to WebAuthenticator.AuthenticateAsync for the above intent filter is as follows: authResult = await WebAuthenticator.AuthenticateAsync( new Uri(authorizeUrl), new Uri("com.mycompanyname.myappname://myoauth2redirect"));
In order to comply with requriements for AppLinks, I tried changing to this intent filter on my callback activity, but the WebAuthenticator.AuthenticateAsync call throws exception "System.InvalidOperationException: 'You must subclass the WebAuthenticatorCallbackActivity and create an IntentFilter for it which matches your callbackUrl.' [Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop)] [IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataScheme = "http", DataHost = "com.mycompanyname.myappname", DataPath = "/myoauth2redirect")]
The (failed) call to WebAuthenticator.AuthenticateAsync for this intent filter is as follows: authResult = await WebAuthenticator.AuthenticateAsync( new Uri(authorizeUrl), new Uri("http://com.mycompanyname.myappname://myoauth2redirect"));
My intent filter I think is like yours, except that I am using "DataPath" while you are using "DataPathPrefix". I don't want a Prefix, as there is only one route that I wish to handle with this IntentFilter, so I think my usage of DataPath is correct. However, just in case I also tried the folloing intent filter to see if using Prefix was helpful, but I got the same exception as in the above failed case. [Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop)] [IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataScheme = "http", DataHost = "com.mycompanyname.myappname", DataPathPrefix = "/Auth/")]
with this call to WebAuthenticator.AuthenticateAsync: authResult = await WebAuthenticator.AuthenticateAsync( new Uri(authorizeUrl), new Uri("http://com.mycompanyname.myappname://Auth/myoauth2redirect"));
Am I formatting the callback Uri incorrectly in the AuthenticateAsync call? Is there something else wrong my filters or calls in the cases that throw exceptions?
Thanks!
Try new Uri("com.mycompanyname.myappname://Auth/myoauth2redirect") and you might need to set your DataPathPrefix="/Auth/myoauth2redirect" as well, not sure. But yeah you are adding the http:// scheme on to your callback URI which is not correct, since your URI scheme is actually 'com.mycompanyname.myappname'
Thanks. I just tried new Uri("com.mycompanyname.myappname://Auth/myoauth2redirect") with both "/Auth/" and "/Auth/myoauth2redirect" as the DataPathPrefix,, but unfortunately I still get the same exception in both cases. I also tried setting "/Auth/myoauth2redirect" as the DataPath instead of DataPathPrefix, and then tried taking the Auth/ part out of both the new Uri definition and the DataPath, but I also get the same exception in both of those cases.
Same problem here. This just does not work.
I've just posted #3184 to get attention to this since I'm not sure anyone monitors comments on closed posts. #3184 can be closed if this item is reopened.
Any progress on this item?
I am struggling on this for 2 days now finding out that it is a known bug. Please repair the bug so we can move forward.
Regards Frank
Any word on this?
Hello Shira,
No word for this. I have found another solution for this. I abandoned Identityserver and OAuth, doing authorization myself. A lot faster and easier in the end.
Regards, Frank van Steenbrugge
Op do 7 okt. 2021 om 14:52 schreef Shira Hammann @.***>:
Any word on this?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/MicrosoftDocs/xamarin-docs/issues/2838#issuecomment-937762827, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJ6Q2IWR4AB54ZBCDJ3LQDUFWJ2LANCNFSM4NCUCGUA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.