public async Task <LoginResultDTO> Refresh() { var user = await UserManager.GetUserAsync(User); if (user is null) { return(new LoginResultDTO { Success = false }); } await SignInManager.RefreshSignInAsync(user); var token = JwtMiddleware.GenerateJwtToken(user, Logger); Logger.LogDebug($"refreshed token for {user.UserName}"); return(new LoginResultDTO { Success = true, Token = token, UserName = user.UserName }); }
public async Task <LoginResultDTO> LogIn( [FromBody] LoginDTO details ) { Logger.LogCritical($"user: {JsonSerializer.Serialize(details)}"); var result = await SignInManager.PasswordSignInAsync(details.Username, details.Password, true, false); if (!result.Succeeded) { return(new LoginResultDTO { Success = false, Token = result.ToString() }); } var user = await CurrentUserAccessor.FindByUsername(details.Username); var token = JwtMiddleware.GenerateJwtToken(user, Logger); Logger.LogDebug($"Logged in {details.Username} with token {token}"); return(new LoginResultDTO { Success = true, Token = token, UserName = user.UserName }); }