I personally worked on a Xamarin/.NET MAUI project couple of years ago. For me, I couldn't get the WebAuthenticator
class to work for me either.
What did work though was using MSAL.NET library and the PublicClientApplication
class. You can follow Migrate Xamarin apps using brokers to MSAL.NET - Microsoft identity platform | Microsoft Learn on switching. As for acquiring tokens, I did what's in the Acquiring tokens interactively - Microsoft Authentication Library for .NET | Microsoft Learn guide.
I did want to the WebAuthenticator
to work due to its simplicity but going the MSAL.net route was more successful.
Callback URL scheme not working with WebAuthenticator for Xamarin app with Azure portal reg.
Hi, I am trying to authenticate my Xamarin app with Azure authentication. I am using Xamarin Essentials WebAuthenticator class for this. I have registered my app on Azure, and also added iOS platform
var url = new Uri("https://login.microsoftonline.com");
var callbackUrl = new Uri("msauth.com.sampleapp://auth");
var res = await WebAuthenticator.AuthenticateAsync(new WebAuthenticatorOptions
{
Url = url,
CallbackUrl = callbackUrl,
PrefersEphemeralWebBrowserSession = true
});
var accessToken = res?.AccessToken;
In the above code, "msauth.com.sampleapp://auth" is the callback URL which is also added in the iOS platform of the Azure app registration. In Info.Plist, I added "msauth.com.sampleapp" in the URLscheme. When i run the app, The azure authentication login page is displayed, and I am able to successfully sign in. But after that, the callback URL is never triggered, and I do not get the access token in the app. Am i missing anything? Is the Callback scheme correct? I am guessing there is something to do with incorrect callback url. I followed the steps given in https://learn.microsoft.com/en-us/xamarin/essentials/web-authenticator?tabs=ios Please let me know. Thanks
1 answer
Sort by: Most helpful
-
Ryan Hill 29,651 Reputation points Microsoft Employee
2024-01-18T17:49:38.1333333+00:00