Skip to content

Instantly share code, notes, and snippets.

@xdumaine
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xdumaine/8690165 to your computer and use it in GitHub Desktop.
Save xdumaine/8690165 to your computer and use it in GitHub Desktop.
public ActionResult OpenId()
{
var response = openId.GetResponse();
if (response == null)
{
return RedirectToAction("Index");
}
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
var fetch = response.GetExtension<FetchResponse>();
string email;
string fullName;
string nickName;
if (fetch != null)
{
email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
fullName = fetch.GetAttributeValue(WellKnownAttributes.Name.FullName);
if (string.IsNullOrEmpty(fullName))
{
fullName = fetch.GetAttributeValue(WellKnownAttributes.Name.First) +
" " + fetch.GetAttributeValue(WellKnownAttributes.Name.Last);
}
nickName = fetch.GetAttributeValue(WellKnownAttributes.Name.Alias);
}
else
{
var claimsResponse = response.GetExtension<ClaimsResponse>();
email = claimsResponse.Email;
fullName = claimsResponse.FullName;
nickName = claimsResponse.Nickname;
}
LoginUser(response.ClaimedIdentifier, response.FriendlyIdentifierForDisplay, email.Trim(), fullName.Trim(), nickName);
return null;
case AuthenticationStatus.Canceled:
ModelState.AddModelError("loginIdentifier",
"Login was cancelled at the provider");
break;
case AuthenticationStatus.Failed:
ModelState.AddModelError("loginIdentifier",
"Login failed using the provided OpenId identifier : " + response.Exception.Message);
break;
}
return Login();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment