-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MsalProvider uses unknown redirect URI, authentication fails #188
Comments
Hello jasonjoh, thank you for opening an issue with us! I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌 |
@jasonjoh this isn't an undocumented url, it's generated from calling this public API in the web authentication broker. As used here:
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? |
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:
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. |
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: // Configure MSAL provider
var msalClient = PublicClientApplicationBuilder.Create(appId)
.WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
.Build();
ProviderManager.Instance.GlobalProvider = new MsalProvider(msalClient, scopes.Split(' ')); |
Just tried passing the redirect to the MsalProvider constructor again to verify. It seems to ignore the value and still use the |
Describe the bug
When using the MsalProvider as documented and as in the sample, auth fails with AADSTS50011.
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
.Configure your provider.
Try to login with the
LoginButton
.Expected behavior
Should login
Environment
The text was updated successfully, but these errors were encountered: