[英]Why do I get URI Mismatch for one account and not another?
Using Azure. My registered app is a Public Client (It's a desktop Appplication).使用 Azure。我注册的应用程序是一个公共客户端(它是一个桌面应用程序)。
The code below works just fine under "USERA"'s account.下面的代码在“USERA”的帐户下工作得很好。
However, running the same code as "USERB" I get the following exception但是,运行与“USERB”相同的代码我得到以下异常
MSAL.NetCore.4.42.0.0.MsalClientException: ErrorCode: loopback_response_uri_mismatch Microsoft.Identity.Client.MsalClientException: Redirect Uri mismatch. MSAL.NetCore.4.42.0.0.MsalClientException:错误代码:loopback_response_uri_mismatch Microsoft.Identity.Client.MsalClientException:重定向 Uri 不匹配。 Expected (/favicon.ico) Actual (/).
预期 (/favicon.ico) 实际 (/)。 at Microsoft.Identity.Client.Platforms.Shared.Desktop.OsBrowser.DefaultOsBrowserWebUi.AcquireAuthorizationAsync(Uri authorizationUri, Uri redirectUri, RequestContext requestContext, CancellationToken cancellationToken) at Microsoft.Identity.Client.Internal.AuthCodeRequestComponent.FetchAuthCodeAndPkceInternalAsync(IWebUI webUi, CancellationToken cancellationToken) at Microsoft.Identity.Client.Internal.AuthCodeRequestComponent.FetchAuthCodeAndPkceVerifierAsync(CancellationToken cancellationToken) at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.GetTokenResponseAsync(CancellationToken cancellationToken) at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.ExecuteAsync(CancellationToken cancellationToken) at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancellationToken)
在 Microsoft.Identity.Client.Platforms.Shared.Desktop.OsBrowser.DefaultOsBrowserWebUi.AcquireAuthorizationAsync(Uri authorizationUri,Uri redirectUri,RequestContext requestContext,CancellationToken cancellationToken)在 Microsoft.Identity.Client.Internal.AuthCodeRequestComponent.FetchAuthCodeAndPkceVerifierAsync(CancellationToken cancellationToken) cancellationToken)在 Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancellationToken)
pubApp = PublicClientApplicationBuilder.Create(config.ClientId)
.WithLogging(Log, LogLevel.Verbose, true)
.WithAuthority(config.Authority)
.WithRedirectUri("http://localhost:12345/")
.Build();
/**
* A call to Graph API calls the following
*/
authResult = await clientApp.AcquireTokenInteractive(scopes)
.WithUseEmbeddedWebView(false)
.WithPrompt(Prompt.SelectAccount)
.ExecuteAsync();
Please check the redirect URI that you are giving in the code.请检查您在代码中提供的重定向 URI。
If your app pops up a window with no address bar, then it is using the " embedded browser "
如果您的应用弹出没有地址栏的 window,那么它正在使用“嵌入式浏览器”
For desktop applications using embedded browser, Microsoft recommend using redirect URI as: https://login.microsoftonline.com/common/oauth2/nativeclient
对于使用嵌入式浏览器的桌面应用程序,Microsoft 建议使用重定向 URI 为:
https://login.microsoftonline.com/common/oauth2/nativeclient
If your app brings your system's default browser (such as Edge, Chrome, Firefox, etc.) to visit Microsoft login portal, then it is using the " system browser ".
如果您的应用程序使用系统默认浏览器(如 Edge、Chrome、Firefox 等)访问 Microsoft 登录门户,那么它正在使用“系统浏览器”。
For desktop applications using system browser, Microsoft recommend using redirect URI as: http://localhost
对于使用系统浏览器的桌面应用程序,Microsoft 建议使用重定向 URI 为:
http://localhost
In the code, you have mentioned .WithUseEmbeddedWebView
( false ) which means you are not using embedded browser.在代码中,您提到
.WithUseEmbeddedWebView
( false ) 这意味着您没有使用嵌入式浏览器。
Please check if both user accounts are using different system browsers.请检查两个用户帐户是否使用不同的系统浏览器。
Try changing redirect URI in .WithRedirectUri() field to something like below as a workaround :尝试将.WithRedirectUri()字段中的重定向 URI 更改为如下所示的解决方法:
"http://localhost:12345"
or "http://localhost"
or "https://localhost"
"http://localhost:12345"
或"http://localhost"
或"https://localhost"
Please find below references if they are helpful.如果有帮助,请查找以下参考资料。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.