1

A windows azure application accept Federated authentication where user can log in using any of the gmail , facebook and live id . Once user is logged in , how can one extract information like getting user name and email id specifically . ?

mohit nagpal
  • 103
  • 11

1 Answers1

2

The email address is presented as a claim from the identity provider.

If you're using MVC (for example) an easy way to read the email address is to add some properties to your controller like this:

public ClaimsPrincipal ClaimsPrincipal
{
    get
    {
        return this.User as ClaimsPrincipal;
    }
}

public ClaimsIdentity ClaimsIdentity
{
    get
    {
        return this.ClaimsPrincipal.Identity as ClaimsIdentity;
    }
}

public string UserEmailAddress
{
    get
    {
        foreach (var claim in this.ClaimsIdentity.Claims)
        {
            if (claim.ClaimType == @"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")
            {
                return claim.Value;
            }
        }
        return null;
    }
}

However, Live ID will not give you the email address, or the user's name.

Richard Astbury
  • 2,323
  • 18
  • 28
  • Live Id give me the user name but not email id . I want to have it to interact with logged in user i.e. sending mails and notification .I think many websites/apps have live id login and they send notification mails on the same id from which user has logged in ... so how they do it ... – mohit nagpal Dec 06 '11 at 19:23
  • They probably ask the user for their email address. – Richard Astbury Dec 06 '11 at 20:57
  • Hmm. This happen sometime . but then there is not point of supporting live login , if user is again asked for email is after login . – mohit nagpal Dec 07 '11 at 18:09
  • I suggest you use Yahoo! and Google then. – Richard Astbury Dec 08 '11 at 09:10