2016-11-28 96 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返回给客户端。如果问题没有解决,请随时通知我。 –

相关问题