为什么没有关于openID用户的信息通过该协议?

Geo*_*Geo 6 openid asp.net-mvc dotnetopenauth

我正在使用DotNetOpenAuth在我们的Web应用程序中集成openID.以下代码向提供商请求信息.

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();
}
Run Code Online (Sandbox Code Playgroud)

出于某种原因,来自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");
    }
Run Code Online (Sandbox Code Playgroud)

我已经尝试过:response.ClaimedIdentifier以百万种方式而且它从来没有我可以做的有价值的信息.有任何想法吗?

And*_*ott 6

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;
  // ...
Run Code Online (Sandbox Code Playgroud)