【问题标题】:Processing concurrent identity provider claims in WIF在 WIF 中处理并发身份提供者声明
【发布时间】:2015-02-23 12:04:46
【问题描述】:

我的 ASP.NET MVC 应用程序使用 WIF 3.5 和 Azure ACS 与 Google、Facebook 等进行联合身份验证。在注册期间,用户通过 IdP 身份验证后,我们将自定义用户数据存储在我们的数据库中。

目前,它允许一个用户帐户与一个身份提供者相关联,但我需要为一个帐户添加对多个身份提供者的支持(即用户可以将 Google、Facebook 等添加到他的帐户和他可以使用其中任何一个 IdP 登录我们的网站)。要将其他 IdP 添加到他的帐户,用户需要先登录到主 IdP。序列是这样的:

  • 用户进入登录页面,选择一个 IdP(例如 Google),登录 Google,Azure ACS 身份验证后重定向回我们的站点
  • 在个人资料页面中,用户选择添加其他 IdP,他被重定向到页面以选择 IdP
  • 他点击另一个 IdP(例如 Facebook),登录 Facebook,Azure ACS 重定向回我们的站点(我可以看到 Facebook 的所有正确声明,即 Azure ACS 传递回我们的站点)
  • 问题是我不确定如何提取这些 Facebook 声明。如果我使用

    HttpContext.Current.User.Identity as Microsoft.IdentityModel.Claims.IClaimsIdentity

它返回 Google(用户登录的当前 IdP)声明

【问题讨论】:

    标签: asp.net authentication azure wif claims


    【解决方案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); 
    

    虽然它有效,但我不确定这是否是最好的方法,所以我仍然将问题留给任何有更好答案的人

    【讨论】:

      猜你喜欢
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-12
      相关资源
      最近更新 更多