azure-ad-msal.net-mauiwebauthenticator

.Net MAUI WebAuthenticator CallbackUrl for social logins


I'm following this guide to setup authenticating with social logins using MSAL and Web Authenticator. The example call looks like this:

WebAuthenticatorResult authResult = await WebAuthenticator.Default.AuthenticateAsync(
    new Uri("https://example.com/mobileauth/Microsoft"),
    new Uri("myapp://"));

But what should the second URI parameter be? In the guide it says:

The URI the flow is expected to ultimately call back to, that is registered to your app.

So how do I register a URI like that to my app?? I've tried following this guide and have 'registered' my app in azure active directory but facebook/google etc won't accept urls of the form "myapp://" as valid redirect URIs... What am I missing?

Update So the first half of the flow is working but I keep getting errors from the OAuth providers (the green highlight in the diagram isn't working). Diagram

This from Google: Google

And this from Facebook: FB

But I've added all these valid callback URLs: urls


Solution

  • Finally got to the bottom of it thanks to this old Xamarin issue: https://github.com/xamarin/Essentials/issues/1224#issuecomment-618192336

    You have to set the "CallbackPath" property in the API config like so:

    .AddGoogle(g => { 
         g.ClientId = "{Client ID}"; 
         g.ClientSecret = "{Client Secret}"; 
         g.CallbackPath = "/mobileauth"; //mobileauth is api controller 
         g.SaveTokens = true; })
    

    And then tell the provider of that redirect e.g. adding "https://{API-URL}/mobileauth" in google console.