public IActionResult RefreshToken([FromServices] IClientDal _dbService, string refToken) { string login = "******"; if (login.Equals("")) { return(NotFound()); } var claims = new[] { new Claim(ClaimTypes.NameIdentifier, login) }; var key = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(Configuration["SecretKey"])); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken ( issuer: "Gakko", audience: "Clients", claims: claims, expires: DateTime.Now.AddMinutes(10), signingCredentials: creds ); Guid refreshToken = Guid.NewGuid(); _dbService.GrandToken(login, refreshToken.ToString()); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token), refreshToken = refreshToken })); }
public IActionResult Login([FromServices] IClientDal _dbService, LoginRequest loginRequest) { if (!_dbService.CheckPassword(loginRequest)) { return(Unauthorized()); } else { var claims = new[] { new Claim(ClaimTypes.NameIdentifier, loginRequest.Login) }; var key = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(Configuration["SecretKey"])); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken ( issuer: "Gakko", audience: "Clients", claims: claims, expires: DateTime.Now.AddMinutes(10), signingCredentials: creds ); Guid refreshToken = Guid.NewGuid(); _dbService.GrandToken(loginRequest.Login, refreshToken.ToString()); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token), refreshToken = refreshToken })); } }