首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >跳过使用Ws-Federation OWIN中间件的主域发现

跳过使用Ws-Federation OWIN中间件的主域发现
EN

Stack Overflow用户
提问于 2015-03-27 13:50:43
回答 1查看 1.9K关注 0票数 3

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

代码语言:javascript
复制
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中间件时执行以下操作:

代码语言:javascript
复制
RedirectToIdentityProvider = (context) =>
{
    context.ProtocolMessage.Whr = "SomeUrnOfAnIdentityProvider";
    return Task.FromResult(0);
}

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

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

代码语言:javascript
复制
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());
    }

在OWIN启动过程中,ws-federation和cookie中间件被配置为第一个中间件,缺省身份验证设置为app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);。

EN

回答 1

Stack Overflow用户

发布于 2015-03-29 01:49:12

我想我找到了一个解决方案。跳过主领域屏幕的新方法如下所示:

代码语言:javascript
复制
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中间件的配置如下:

代码语言:javascript
复制
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
    }    
});
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29294162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档