[英]Why do I get URI Mismatch for one account and not another?
使用 Azure。我注册的应用程序是一个公共客户端(它是一个桌面应用程序)。
下面的代码在“USERA”的帐户下工作得很好。
但是,运行与“USERB”相同的代码我得到以下异常
MSAL.NetCore.4.42.0.0.MsalClientException:错误代码:loopback_response_uri_mismatch Microsoft.Identity.Client.MsalClientException:重定向 Uri 不匹配。 预期 (/favicon.ico) 实际 (/)。 在 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();
请检查您在代码中提供的重定向 URI。
如果您的应用弹出没有地址栏的 window,那么它正在使用“嵌入式浏览器”
对于使用嵌入式浏览器的桌面应用程序,Microsoft 建议使用重定向 URI 为: https://login.microsoftonline.com/common/oauth2/nativeclient
如果您的应用程序使用系统默认浏览器(如 Edge、Chrome、Firefox 等)访问 Microsoft 登录门户,那么它正在使用“系统浏览器”。
对于使用系统浏览器的桌面应用程序,Microsoft 建议使用重定向 URI 为: http://localhost
在代码中,您提到.WithUseEmbeddedWebView
( false ) 这意味着您没有使用嵌入式浏览器。
请检查两个用户帐户是否使用不同的系统浏览器。
尝试将.WithRedirectUri()字段中的重定向 URI 更改为如下所示的解决方法:
"http://localhost:12345"
或"http://localhost"
或"https://localhost"
如果有帮助,请查找以下参考资料。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.