我正在关注本文以实现OAuth身份验证: http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on 您可以找到ExternalLoginCallback控制器的操作. 在该操作中执
http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on
您可以找到ExternalLoginCallback控制器的操作.
在该操作中执行以下方法:
ExternalLoginInfo loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
loginInfo有Login属性. Login属性具有LoginProvider和ProviderKey属性.
有谁知道它是什么ProviderKey属性?是注册到提供商的唯一UserID吗?
谢谢
尝试User.Identity.GetUserId()方法.if (loginInfo == null) { return View("ExternalLoginFailure"); } var userId = User.Identity.GetUserId();
有关更多信息,请参阅Get more information from Social providers used in the VS 2013 project templates帖子.
更新:获取用户的另一种方式是:
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); if (loginInfo == null) { return RedirectToAction("Login"); } var user = await UserManager.FindAsync(loginInfo.Login); if (user != null) { await SignInAsync(user, isPersistent: false); return RedirectToLocal(returnUrl); }