2016-11-28 86 views
0

我正在使用Azure AD與OpenIdConnect和一個回覆URL網站,但我需要通過LocalHost進行連接以進行測試並實現其他功能。使用OpenIDConnect在Azure AD應用程序中回覆URL

如何使用UseOpenIdConnectAuthentication使用UseOpenIdConnectAuthentication獲取多於一個的回覆URL,而且兩者都不會丟失訪問權限。

我的應用程序配置了Asp.Net Web.Forms(Visual Studio 2015)。

Tks。

維萊拉

回答

0

是的,它的作品,但我需要實現別人的代碼,例如:

RedirectToIdentityProvider = (context) => 
        { 
         // This ensures that the address used for sign in and sign out is picked up dynamically from the request 
         // this allows you to deploy your app (to Azure Web Sites, for example)without having to change settings 
         // Remember that the base URL of the address used here must be provisioned in Azure AD beforehand. 
         string appBaseUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase; 
         context.ProtocolMessage.RedirectUri = appBaseUrl; 
         context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl; 
         return System.Threading.Tasks.Task.FromResult(0); 
        }, 

但是,我有問題,多租戶。其他用戶在我的租戶中進行身份驗證。這是我的問題還是Azure問題?

韓國社交協會, 維萊拉

1

是的,這是可能的dynamiclly使用RedirectToIdentityProvider改變回覆URL。您可以參考下面的代碼示例:

app.UseOpenIdConnectAuthentication(
      new OpenIdConnectAuthenticationOptions 
      { 
       ClientId = clientId, 
       Authority = authority, 
       PostLogoutRedirectUri = postLogoutRedirectUri, 
       RedirectUri = postLogoutRedirectUri, 
       Notifications = new OpenIdConnectAuthenticationNotifications 
       { 
        AuthenticationFailed = context => 
        { 
         context.HandleResponse(); 
         context.Response.Redirect("/Error?message=" + context.Exception.Message); 
         return Task.FromResult(0); 
        }, 
        RedirectToIdentityProvider=(context)=> 
        { 
         context.ProtocolMessage.RedirectUri = ""; 
         return Task.FromResult(0); 
        } 
       } 
      }); 

但是,如果應用程序已經部署到Web服務器上,更改重定向URL到本地主機可能無法按你的預期,因爲有對網絡兩種不同的應用程序服務器應用運行。

+0

什麼這意味着是,你會手動將重定向URI請求URI?聽起來像是唯一的方法.. – juunas

+0

謝謝你的回報,但我不明白爲什麼要更改Azure AD中的重定向URL。它不是自動的? – Vilela

+0

您在Azure門戶上註冊應用程序的重定向URL與您在請求中傳遞的重定向URL之間有所不同。 Azure廣告將根據門戶上的值寄存器驗證傳遞的重定向URL。如果該值被驗證,則Azure AD會將此URL返回給客戶端。如果問題沒有解決,請隨時通知我。 –

相關問題