【问题标题】:Why isn't information about the openID user coming through the protocol?为什么有关 openID 用户的信息不通过协议传递?
【发布时间】:2009-09-08 12:18:49
【问题描述】:

我正在使用DotNetOpenAuth 将openID 集成到我们的Web 应用程序中。下面的代码向提供者请求信息。

try
{
  var req = openid.CreateRequest(Request.Form["openid_identifier"]);
  req.AddExtension(new DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.ClaimsRequest
  {
    Email = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Require,
    FullName = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Require,
    Nickname = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Request,
    PostalCode = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Request
  });

  return req.RedirectingResponse.AsActionResult();
}

出于某种原因,来自 openID 提供者的响应从未附带我请求的信息。下面是代码:

// Stage 3: OpenID Provider sending assertion response
switch (response.Status) {
  case AuthenticationStatus.Authenticated:
    Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
    FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
    if (!string.IsNullOrEmpty(returnUrl)) {
       return Redirect(returnUrl);
    } else {
       return RedirectToAction("Index", "Home");
    }

我已经尝试过:response.ClaimedIdentifier 以一百万种方式,但它从来没有有价值的信息可以用来做某事。有什么想法吗?

【问题讨论】:

    标签: asp.net-mvc openid dotnetopenauth


    【解决方案1】:

    IAuthenticationResponse.ClaimedIdentifier 属性从不 包含您请求的这些属性。它只包含 OpenID 用户的“用户名”。

    您正在完美地发送请求。只需在您对积极响应的处理中添加一点:

    // Stage 3: OpenID Provider sending assertion response
    switch (response.Status) { 
      case AuthenticationStatus.Authenticated:
        Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay; 
        FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
        var sreg = response.GetExtension<ClaimsResponse>();
        if (sreg != null) { // the Provider MAY not provide anything
          // and even if it does, any of these attributes MAY be missing
          var email = sreg.Email;
          var fullName = sreg.FullName;
          // get the rest of the attributes, and store them off somewhere.
        }
        if (!string.IsNullOrEmpty(returnUrl)) {
          return Redirect(returnUrl);
        } else {
           return RedirectToAction("Index", "Home");
        }
      break;
      // ...
    

    【讨论】:

    • 嗨安德鲁:非常感谢它的工作原理。谷歌回馈电子邮件,雅虎没有。感谢您的帮助。
    • 雅虎应该是现在......他们刚刚升级以支持它。
    猜你喜欢
    • 2022-09-29
    • 2018-07-28
    • 2015-11-27
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多