public async Task <ActionResult <AuthResponseDTO> > Login(AccountCredentialsDTO credentials) { var user = await userManager.FindByNameAsync(credentials.Email); if (user == null) { return(Unauthorized()); } if (!await userManager.CheckPasswordAsync(user, credentials.Password)) { return(Unauthorized()); } var accessToken = tokenGenerator.GenerateAccessToken(user); var refreshToken = tokenGenerator.GenerateRefreshToken(); context.RefreshTokens.Add(new RefreshToken { Token = refreshToken, Expiration = DateTime.Now.Add(tokenGenerator.Options.RefreshExpiration), UserId = user.Id }); context.SaveChanges(); var response = new AuthResponseDTO { AccessToken = accessToken, RefreshToken = refreshToken, UserId = user.Id, Username = user.UserName }; return(response); }
public async Task <ActionResult <AuthResponseDTO> > Login(AccountCredentialsDTO credentials) { var user = await userManager.FindByNameAsync(credentials.Email); if (user == null) { return(Unauthorized()); } if (!await userManager.CheckPasswordAsync(user, credentials.Password)) { return(Unauthorized()); } var accessToken = tokenGenerator.GenerateAccessToken(user); var authUser = new AuthResponseDTO { AccessToken = accessToken, UserId = user.Id, UserName = user.UserName }; return(authUser); }
/// <summary> /// /// </summary> /// <param name="credentials"></param> /// <remarks>Author: Scott Roberts</remarks> private void PostNewPasswordToSSO(AccountCredentialsDTO credentials) { // Call request service to make a request to the SSO. using (var client = HttpClientService.Instance) { // The request should talk to the SSO controller to talk to the database. // The request should handle all successes and errors, or pass it off. } // We then need to save the User to our database. //using(var context = new ECSContext()) // The return should be a Json object to the SSO server. //return new HttpStatusCodeResult(HttpStatusCode.OK); }
public async Task <IActionResult> Register(AccountCredentialsDTO credentials) { var user = new IdentityUser { Email = credentials.Email, UserName = credentials.Email }; var result = await userManager.CreateAsync(user, credentials.Password); if (!result.Succeeded) { return(BadRequest(result.Errors)); } return(Ok()); }