【发布时间】:2017-03-08 14:24:44
【问题描述】:
尝试将带有 LinkedIN 功能的注册/登录功能添加到我的网络应用程序。这是我调用 api 的 ExternalLoginCallback 方法。
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
// Sign in the user with this external login provider if the user already has a login
var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
case SignInStatus.Failure:
default:
// If the user does not have an account, then prompt the user to create an account
ViewBag.ReturnUrl = returnUrl;
ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
var externalIdentity = HttpContext.GetOwinContext().Authentication.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
var firstName = externalIdentity.Result.Claims.FirstOrDefault(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname").Value;
var lastName = externalIdentity.Result.Claims.FirstOrDefault(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname").Value;
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email, Name = firstName });
}
}
尝试捕获 externalIdentity 从linkedIN 获取的内容并得到了这个:
如您所见,根据 LinkedIn (https://developer.linkedin.com/docs/fields/basic-profile),只有 11 个字段,但应该有更多字段
我怎样才能得到其余的?喜欢图片网址,还是第二个位置? (由于某种原因,它只返回第一个)
谢谢
【问题讨论】:
标签: c# asp.net-mvc-5 oauth-2.0 linkedin-api