public IActionResult RefreshToken(string token) { var user = _service.CheckRefreshToken(token); if (user == null) { return(Forbid("Bearer")); } var claims = _service.GetClaims(user); var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["SecretKey"])); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var newToken = new JwtSecurityToken( issuer: "Gakko", audience: "Students", claims: claims, expires: DateTime.Now.AddMinutes(5), signingCredentials: creds ); var refreshToken = Guid.NewGuid(); _service.SetRefreshToken(refreshToken.ToString(), user); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(newToken), refreshToken })); }
public IActionResult RefreshToken(LoginRequestDTO request, string refreshToken) { if (_service.CheckRefreshToken(refreshToken, request.Login)) { var claims = new[] { new Claim(ClaimTypes.NameIdentifier, request.Login) }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["SecretKey"])); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken ( issuer: "School", audience: "Students", claims: claims, expires: DateTime.Now.AddMinutes(10), signingCredentials: creds ); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token) })); } return(StatusCode(401)); }
public IActionResult RefreshToken(string refreshToken) { string login = _dbService.CheckRefreshToken(refreshToken); if (login == "") { return(Unauthorized()); } return(Ok(GenerateToken(login))); }
public IActionResult RefreshToken(string tokenString) { string indexNum = _dbService.CheckRefreshToken(tokenString); if (indexNum == null) { return(Unauthorized()); } var claims = new[] { new Claim(ClaimTypes.NameIdentifier, "1"), new Claim(ClaimTypes.Name, "login"), new Claim(ClaimTypes.Role, "admin"), new Claim(ClaimTypes.Role, "student"), new Claim(ClaimTypes.Role, "employee") }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["SecretKey"])); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken ( issuer: "s18533", audience: "Students", claims: claims, expires: DateTime.Now.AddMinutes(10), signingCredentials: creds ); var refToken = Guid.NewGuid(); _dbService.AddRefreshToken(refToken, indexNum); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token), refreshToken = refToken })); }