我们的Mvc / WebAPI解决方案目前有四个可信身份提供商,我们已在ADFS3中注册。我们的用户可以通过直接链接使用这些身份提供者中的每一个,有效地解决ADFS可能创建的任何家庭领域 - 例如: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);
答案 0 :(得分:4)
我想我找到了解决方案。跳过主域界面的新方法如下:
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
}
});