簡體   English   中英

為什么我得到一個帳戶的 URI 不匹配,而另一個帳戶卻沒有?

[英]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"

如果有幫助,請查找以下參考資料。

參考文獻: Ref1Ref2Ref3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM