You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the MsalProvider as documented and as in the sample, auth fails with AADSTS50011.
Request Id: 5e464c00-92a4-4a14-a5e6-f6c807527900
Correlation Id: 70fa290d-da9e-4a48-ac59-98da60a73410
Timestamp: 2022-04-29T14:51:55Z
Message: AADSTS50011: The redirect URI 'ms-appx-web://Microsoft.AAD.BrokerPlugin/S-1-15-2-3827128064-569582487-4294593430-3382639814-4294318972-3676523608-2734131615' specified in the request does not match the redirect URIs configured for the application '3892d014-2554-4df7-a10b-9f1e5c0742e7'. Make sure the redirect URI sent in the request matches one added to your application in the Azure portal. Navigate to https://aka.ms/redirectUriMismatchError to learn more about how to fix this.
Is this bug a regression in the toolkit? If so, what toolkit version did you last see it work:
Steps to Reproduce
Steps to reproduce the behavior:
Register an app in Azure AD using the redirect URI https://login.microsoftonline.com/common/oauth2/nativeclient.
@shweaver-MSFT is this something we should call out in the docs, this url just needs to be registered in Azure right? As the default one is only recommended for embedded browsers?
If you don't mind, @jasonjoh, try out what @michael-hawker suggested. I'm curious if that works for you. The guidance in the README/docs certainly doesn't tell you to do this for the MsalProvider, so I can see why you are confused. When I wrote the docs it didn't seem to be a requirement to use that custom redirect URI, only for the WindowsProvider. But perhaps something has changed since then.
Oh actually... looking at this closer, I can see that you aren't specifying a redirect uri when you create the MsalProvider instance:
string[] scopes = new string[] { "User.Read" };
ProviderManager.Instance.GlobalProvider =
new MsalProvider("CLIENT_ID", scopes);
Somewhere in MsalProvider, if you don't provide a redirect uri it will attempt to figure it out for you. I think the part you missed is actually passing that redirect uri into the constructor:
string[] scopes = new string[] { "User.Read" };
string redirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient";
ProviderManager.Instance.GlobalProvider =
new MsalProvider("CLIENT_ID", scopes, redirectUri);
I didn't think this was necessary, but I can tell by the error message you showed that Msal is picking a very different redirect uri than what the docs recommend. The other option is to go the other way, and add the url it listed in the error message back into your azure config.
Yeah, it worked. That was the first thing I did to resolve the error, but opened this issue as it's not a great experience to have to run the app to get an error so you then know what redirect to add to your app registration. :D
I did try passing the static redirect to the constructor for MsalProvider, but that didn't work for me. I had to do this:
Activity
michael-hawker commentedon Jun 14, 2022
@jasonjoh this isn't an undocumented url, it's generated from calling this public API in the web authentication broker.
As used here:
Graph-Controls/CommunityToolkit.Authentication.Uwp/WindowsProvider.cs
Line 49 in 15513b1
Did you try the steps in the url provided by the error message? https://aka.ms/redirectUriMismatchError
@shweaver-MSFT is this something we should call out in the docs, this url just needs to be registered in Azure right? As the default one is only recommended for embedded browsers?
shweaver-MSFT commentedon Jun 14, 2022
If you don't mind, @jasonjoh, try out what @michael-hawker suggested. I'm curious if that works for you. The guidance in the README/docs certainly doesn't tell you to do this for the MsalProvider, so I can see why you are confused. When I wrote the docs it didn't seem to be a requirement to use that custom redirect URI, only for the WindowsProvider. But perhaps something has changed since then.
shweaver-MSFT commentedon Jun 14, 2022
Oh actually... looking at this closer, I can see that you aren't specifying a redirect uri when you create the MsalProvider instance:
Somewhere in MsalProvider, if you don't provide a redirect uri it will attempt to figure it out for you. I think the part you missed is actually passing that redirect uri into the constructor:
I didn't think this was necessary, but I can tell by the error message you showed that Msal is picking a very different redirect uri than what the docs recommend. The other option is to go the other way, and add the url it listed in the error message back into your azure config.
[-]MsalProvider uses undocumented redirect URI, authentication fails[/-][+]MsalProvider uses unknown redirect URI, authentication fails[/+]jasonjoh commentedon Jun 14, 2022
Yeah, it worked. That was the first thing I did to resolve the error, but opened this issue as it's not a great experience to have to run the app to get an error so you then know what redirect to add to your app registration. :D
I did try passing the static redirect to the constructor for MsalProvider, but that didn't work for me. I had to do this:
jasonjoh commentedon Jun 14, 2022
Just tried passing the redirect to the MsalProvider constructor again to verify. It seems to ignore the value and still use the
ms-appx-webURL.