public async Task <IActionResult> TokenSigninGoogle(string user) { var userInfoFromWebApp = JsonConvert.DeserializeObject <GoogleUserInfo>(user); var validatedLoginInfoFromGoogle = await GoogleJsonWebSignature.ValidateAsync(userInfoFromWebApp.IdToken, new GoogleJsonWebSignature.ValidationSettings { Audience = new List <string> { _configuration.GetGoogleClientId() } }); var userInSystem = await _userManager.FindByEmailAsync(validatedLoginInfoFromGoogle.Email); if (userInSystem == null) { userInSystem = new UserModel { Email = validatedLoginInfoFromGoogle.Email, UserName = validatedLoginInfoFromGoogle.Email, PersonName = $"{validatedLoginInfoFromGoogle.FamilyName} {validatedLoginInfoFromGoogle.GivenName}" }; var result = await _userManager.CreateAsync(userInSystem); if (!result.Succeeded) { return(Unauthorized()); } else { result = await _userManager.AddLoginAsync(userInSystem.Id, new UserLoginInfo(GOOGLE, userInSystem.Email)); if (!result.Succeeded) { _userManager.DeleteAsync(userInSystem).Wait(); return(Unauthorized()); } } } var ident = await _userManager.CreateIdentityAsync( userInSystem, DefaultAuthenticationTypes.ApplicationCookie); if (IsBlocked(ident.GetUserId <int>())) { return(Unauthorized()); } ident.AddClaims( new List <Claim> { new Claim(nameof(validatedLoginInfoFromGoogle.Name), validatedLoginInfoFromGoogle.Email), new Claim(nameof(validatedLoginInfoFromGoogle.FamilyName), validatedLoginInfoFromGoogle.FamilyName), new Claim(nameof(validatedLoginInfoFromGoogle.GivenName), validatedLoginInfoFromGoogle.GivenName) }); await HttpContext.SignOutAsync(COOKIE_NAME); await HttpContext.SignInAsync(COOKIE_NAME, new ClaimsPrincipal(ident), new AuthenticationProperties { IsPersistent = false } ); return(Ok()); }