public Task<ClaimsIdentity> CreateIdentityAsync(FoodRUser user, string authenticationType) { return userManager.CreateIdentityAsync(user, authenticationType); }
public Task<IdentityResult> CreateUserAsync(FoodRUser user) { return userManager.CreateAsync(user); }
private async Task<SignInStatus> SignInOrTwoFactor(FoodRUser user, bool isPersistent) { if (await GetTwoFactorEnabledAsync(user.Id) && !await TwoFactorBrowserRememberedAsync(user.Id)) { var identity = new ClaimsIdentity(DefaultAuthenticationTypes.TwoFactorCookie); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id)); SignIn(identity); return SignInStatus.RequiresTwoFactorAuthentication; } await SignInAsync(user, isPersistent, false); return SignInStatus.Success; }
public async Task SignInAsync(FoodRUser user, bool isPersistent, bool rememberBrowser) { // Clear any partial cookies from external or two factor partial sign ins SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie); var userIdentity = await user.GenerateUserIdentityAsync(userManager); if (rememberBrowser) { var rememberBrowserIdentity = CreateTwoFactorRememberBrowserIdentity(user.Id); SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, userIdentity, rememberBrowserIdentity); } else { SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, userIdentity); } }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return RedirectToAction("Index", "Manage"); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await userService.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new FoodRUser { UserName = model.Email, Email = model.Email }; var result = await userService.CreateUserAsync(user); if (result.Succeeded) { result = await userService.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await userService.SignInAsync(user, isPersistent: false, rememberBrowser: false); return RedirectToLocal(returnUrl); } } AddIdentityErrors(result); } ViewBag.ReturnUrl = returnUrl; return View(model); }