Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't information about the openID user coming through the protocol?

I am using DotNetOpenAuth to integrate openID in our web application. The code below requests the information to the provider.

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();
}

For some reason the response from the openID provider never comes with the information I am requesting. Below is the code:

// 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");
    }

I have tried: response.ClaimedIdentifier in a million ways and it never has valuable information that I can do something with. Any ideas?

like image 767
Geo Avatar asked Sep 08 '09 12:09

Geo


People also ask

What protocol is the basis for OpenID Connect?

OpenID Connect is a simple identity protocol and open standard that is built using the OAuth 2.0 protocol. It enables client applications to rely on authentication that is performed by an OpenID Connect Provider to verify the identity of a user.

Is OpenID a protocol?

OpenID Connect (OIDC) is an open authentication protocol that works on top of the OAuth 2.0 framework.


1 Answers

The IAuthenticationResponse.ClaimedIdentifier property never contains these attributes that you're requesting. It only contains the "username" of the OpenID user.

You're sending the request perfectly. Just add a bit to your handling of the positive response:

// 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;
  // ...
like image 184
Andrew Arnott Avatar answered Oct 27 '22 19:10

Andrew Arnott