Question

I'm Trying to login with dotNetOpenId to GMail accounts. It works but I'm not able to retrieve any claims. I know I could retrieve email addresses or user names as well, but no claims are being returned only the ClaimedIdentifier is available. Anyone know how to retrieve this data from Gmail accounts? If you could please provide me an example of ClaimsRequest configuration I would be grateful.

Thanks

Was it helpful?

Solution

// Either you're creating this already or you can get to it in 
// the LoggingIn event of the control you're using.

IAuthenticationRequest request;

// Add the AX request that says Email address is required.
var fetch = new FetchRequest();
fetch.Attributes.Add(
    new AttributeRequest(WellKnownAttributes.Contact.Email, true));
request.AddExtension(fetch);

Google then authenticates the user and returns the email address, which you can get with:

var fetch = openid.Response.GetExtension<FetchResponse>();  
if (fetch != null) 
{  
    IList<string> emailAddresses = fetch.GetAttribute(
        WellKnownAttributes.Contact.Email).Values;  
    string email = emailAddresses.Count > 0 ? emailAddresses[0] : null;  
}

You can see my blog post on the subject for a bit more information. The important thing to note here is that Google will only tell you the user's email address if you mark it as required (as I have done in the above snippet). But this also means that if the user does not want to share his email address, he cannot log in at all. Sorry, that's the way Google set it up. Other Providers that people use have different behaviors, unfortunately.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top