我的ASP.NET MVC应用程序正在使用WIF 3.5和Azure ACS与Google,Facebook等进行联合身份验证。在注册期间,用户通过IdP进行身份验证后,我们会将自定义用户数据存储在我们的数据库中。 / p>
目前,它允许一个用户帐户与一个身份提供商关联,但我要求为一个帐户添加对多个身份提供商的支持(.ie用户可以将Google,Facebook等添加到他的帐户中他可以使用这些IdP中的任何一个登录我们的网站)。要向其帐户添加其他IdP,用户需要先登录主IdP。序列是这样的:
问题是我不确定如何提取这些Facebook声明。如果我使用
HttpContext.Current.User.Identity as Microsoft.IdentityModel.Claims.IClaimsIdentity
它返回Google(用户登录时的当前IdP)声明
答案 0 :(得分:1)
最后,我需要阅读回复并手动将其解析为声明,这里我是如何做的,仅供参考:
//Response from Azure ACS is stored in wresult parameter
string samlResponse = Request.Params["wresult"];
var xmlTextReader = new XmlTextReader(new StringReader(samlResponse));
//Only interested in Assertion section of the response
xmlTextReader.ReadToFollowing("Assertion", "urn:oasis:names:tc:SAML:2.0:assertion");
SecurityTokenHandlerCollection handlers = FederatedAuthentication.ServiceConfiguration.SecurityTokenHandlers;
// read the token
var securityToken = handlers.ReadToken(xmlTextReader);
// validate the token and create the identity collection
var claimsIdentityCollection = handlers.ValidateToken(securityToken);
// create ClaimsPrincipal
var claimsPrincipal = new ClaimsPrincipal(claimsIdentityCollection);
虽然它有效,但我不确定这是否是最好的方法,所以我仍然会为那些有更好答案的人留下问题