public async Task <ActionResult> ExternalLoginCallback(string returnUrl) { string userid = null; string LogUserName = null; var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); if (loginInfo == null) { return(RedirectToAction("Login")); } //No need to mail conf, because we register under logged provider string userprokey = loginInfo.Login.ProviderKey; userid = _dbhelpers.FindUserId(userprokey); //get userId by login provider key if (userid != null) { LogUserName = _dbhelpers.FindUserNameById(userid); //get username } // 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: _dbhelpers.UpdateLastLoginDate(LogUserName); //update last login date _dbhelpers.UpdateOnlineStatus(LogUserName); //update online status 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; return(View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email })); } }