【问题标题】:Skipping home realm discovery with Ws-Federation OWIN Middleware使用 Ws-Federation OWIN 中间件跳过家庭领域发现
【发布时间】:2015-05-31 09:30:34
【问题描述】:

我们的 Mvc/WebAPI 解决方案目前有四个我们已在 ADFS3 中注册的可信身份提供者。我们的用户可以通过直接链接使用这些身份提供者中的每一个,从而有效地解决 ADFS 可能创建的任何 home-realm-cookie(例如:www.ourportal.com/accounts/facebook 或 www.ourportal.com/accounts/推特)。目前我们正在从 WIF 迁移到 OWIN,但将通过实现 wsfederation 和 cookie 身份验证中间件暂时继续使用 WS-Federation 协议。使用 WIF 时,为了直接访问已知身份提供者,我们执行了以下操作:

var signInRequest = new SignInRequestMessage(stsUrl, realm) { HomeRealm = homeRealm };
return new RedirectResult(signInRequest.WriteQueryString());

这似乎有两个相关的行为,它没有传递 WsFedOwinState 参数,并且在返回到依赖方时,在 Owin 身份验证中间件被触发之前构建 Home.cshtml(使用 windows 主体)。在 Owin 中间件之前触发的 Home.cshtml 是最令人担忧的,因为此视图依赖于将在身份验证管道完成的转换中提供的声明,该转换随后被触发,因此我们的视图不起作用。当以正常方式访问门户时(例如 www.ourportal.com),它以正确的顺序工作

我了解到,为了提供 Whr 参数,您在配置 ws-federation 中间件时请执行以下操作:

RedirectToIdentityProvider = (context) =>
{
    context.ProtocolMessage.Whr = "SomeUrnOfAnIdentityProvider";
    return Task.FromResult(0);
}

但这为整个解决方案设置了一个身份提供者,并且不允许我们的用户直接访问身份提供者列表中的一个。

当前构建登录请求的非工作方法是:

private RedirectResult FederatedSignInWithHomeRealm(string homeRealm)
{
    var stsUrl = new Uri(ConfigurationManager.AppSettings["ida:Issuer"]);
    string realm = ConfigurationManager.AppSettings["ida:Audience"];

    var signInRequest = new SignInRequestMessage(stsUrl, realm)
    {
        HomeRealm = homeRealm
    };
 HttpContext.Request.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
        return new RedirectResult(signInRequest.WriteQueryString());
    }

ws-federation 和 cookie 中间件被配置为 OWIN 启动的第一个中间件,默认认证设置为 app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

【问题讨论】:

    标签: owin


    【解决方案1】:

    我想我找到了解决办法。跳过主领域屏幕的新方法是这样的:

    private void FederatedSignInWithHomeRealm(string homeRealm)
    {
        HttpContext.Request
                   .GetOwinContext()
                   .Authentication
                   .SignOut(CookieAuthenticationDefaults.AuthenticationType);
        var authenticationProperties = new AuthenticationProperties { RedirectUri = "/" };
        authenticationProperties.Dictionary.Add("DirectlyToIdentityProvider", homeRealm);
        HttpContext.GetOwinContext().Authentication.Challenge(authenticationProperties);
    }
    

    OWIN WS-Federation 中间件的配置如下:

    app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
    {
        Notifications = new WsFederationAuthenticationNotifications()
        {
            RedirectToIdentityProvider = notification =>
            {
                string homeRealmId = null;
                var authenticationResponseChallenge = notification.OwinContext
                                                                  .Authentication
                                                                  .AuthenticationResponseChallenge;
                var setIdentityProvider = authenticationResponseChallenge != null 
                                          && authenticationResponseChallenge.Properties
                                                                            .Dictionary
                                                                            .TryGetValue("DirectlyToIdentityProvider", out homeRealmId);
                if (setIdentityProvider)
                {
                    notification.ProtocolMessage.Whr = homeRealmId;
                }
                return Task.FromResult(0);
            }
        },
        MetadataAddress = wsFedMetadata,
        Wtrealm = realm,
        SignInAsAuthenticationType =     CookieAuthenticationDefaults.AuthenticationType,
        TokenValidationParameters = new TokenValidationParameters
        {
            ValidAudience = realm
        }    
    });
    

    【讨论】:

      猜你喜欢
      • 2014-04-20
      • 1970-01-01
      • 2016-12-07
      • 2012-11-27
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多