Last active
August 29, 2015 13:55
-
-
Save xdumaine/8690165 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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