OWIN OAuth .NET中如何获取用户ID实现登录认证?
- 内容介绍
- 文章标签
- 相关推荐
本文共计257个文字,预计阅读时间需要2分钟。
我在关注如何通过实现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控制器的操作?在操作中执行以下内容:
我正在关注本文以实现OAuth身份验证: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); }
本文共计257个文字,预计阅读时间需要2分钟。
我在关注如何通过实现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控制器的操作?在操作中执行以下内容:
我正在关注本文以实现OAuth身份验证: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); }

