How to get UserID in OWIN OAuth.NET

I am following this article to achieve OAuth authentication: -openid-sign-on

You can find the ExternalLoginCallback controller action. This activity runs the following method:

ExternalLoginInfo loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();


loginInfo has a login property. The Login property has properties LoginProvider and ProviderKey.

Does anyone know what is the ProviderKey property? Is it a unique UserID registered with the provider?



source to share

1 answer

try the User.Identity.GetUserId()


if (loginInfo == null)
    return View("ExternalLoginFailure");

var userId = User.Identity.GetUserId();


for more information, see Get more information from social providers used in VS 2013 project templates .

Update: Another way to get the user:

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);




All Articles