2017-01-16 59 views
4

鉴于IdentitySever3重定向URL多个域

一个ASP MVC网站IIS。该网站用身份识别服务器以非正式流程对用户进行身份验证。

有多个域被攻击。所以该网站是从不同的域名。例如

  • foo.com
  • foo.de
  • foo.fr

问题

现在,当我配置我的网站,我必须设置重定向URL,但它取决于关于用户来自哪里。但是,由于此配置是在应用程序启动时完成的,因此根据传入的请求我无法改变。

这是什么推荐的方法?

public static void Configure(IAppBuilder app) 
{ 
     app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
      { 
       AuthenticationType = "oidc", 
       Authority = ConfigurationManager.AppSettings["authority"], 
       ClientId = "BlsFrontend", 
       RedirectUri = "http://foo.de", //how to get this dynamically? 
       ResponseType = "id_token token", 
       SignInAsAuthenticationType = "Cookies", 
       Scope = "openid profile", 

有一件事我在考虑是使用RedirectToIdentityProvider通知和adpot在请求重定向。我测试过它,它适用于我的情况,但这是否是一种有效/好的方法?

RedirectToIdentityProvider = n => 
{ 
    if (!string.IsNullOrWhiteSpace(n.ProtocolMessage.RedirectUri)) 
    { 
     n.ProtocolMessage.RedirectUri = n.Request.Scheme + "://" + n.Request.Host.ToString(); //How to make it clean !? 
    } 
} 
+0

这是正确的方式,RedirectUri由权威机构验证。 –

回答

0

我张贴这是因为我没有发现任何其他的解决问题和其他一些人也采用了这种解决方案

的解决方案是正确的之前设置重定向URL根据请求的解决方案我们被重定向到身份服务器。为此,我使用RedirectToIdentityProvider通知

RedirectToIdentityProvider = n => 
{ 

    if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.Authentication && 
     !string.IsNullOrWhiteSpace(n.ProtocolMessage.RedirectUri)) 
    { 
     n.ProtocolMessage.RedirectUri = n.Request.Scheme + "://" + n.Request.Host.ToString(); //How to make it clean !? 
    } 
}