views:

880

answers:

2

I’m using dotnetopenauth 3.2 to implement Openid and can’t figure out how to get Google to pass the email address in the Claims Response. I know that Google doesn’t support simple registration, but I can’t determine what they do support.

Caveat to this question is that I just started learning OpenID and I know I don’t have a solid grasp on the specification which I think is leading to my confusion.

Any help would be appreciated!

+8  A: 

Ok figured it out. I posted a question on Goolge's Federated Log API group http://groups.google.com/group/google-federated-login-api/browse%5Fthread/thread/5521cae736698091# and was told to use Attribute exchange. Below is the code for Dotnetopenauth.

Please don't use this code in production! for illustration purposes only

//The Request
 using (OpenIdRelyingParty openid = new OpenIdRelyingParty())
 {
   IAuthenticationRequest request = openid.CreateRequest(openidurl);

    var fetch = new FetchRequest();
    fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
    request.AddExtension(fetch);

    // Send your visitor to their Provider for authentication.
    request.RedirectToProvider();
 }


//The Response
 OpenIdRelyingParty openid = new OpenIdRelyingParty();
 var response = openid.GetResponse();
 if (response != null)
 {
         switch (response.Status)
         {
             case AuthenticationStatus.Authenticated:

             var fetch = response.GetExtension<FetchResponse>();
             string email = string.Empty(); 
             if (fetch != null)
             {
                email =  fetch.GetAttributeValue(WellKnownAttributes.Contact.Email)
             }  

             FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, false);
          break;
          }
}
Zaffiro
A: 

Did you by any chance try to retrieve the country field? I've tried both

ClaimsRequest { Country = DemandLevel.Require }

and

FetchRequest fetchRequest = new FetchRequest(); fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.HomeAddress.Country); fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.WorkAddress.Country);

without any luck.

Thanks

Senthuran