Created
July 22, 2019 14:54
-
-
Save ntakouris/49e317e307b8ebc45553c30a68140b69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var tokenDescriptor = new SecurityTokenDescriptor | |
| { | |
| Subject = new ClaimsIdentity(claims), | |
| Expires = DateTime.UtcNow.Add(_jwtSettings.TokenLifetime), | |
| SigningCredentials = | |
| new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) | |
| }; | |
| var token = tokenHandler.CreateToken(tokenDescriptor); | |
| var refreshToken = new RefreshToken | |
| { | |
| JwtId = token.Id, | |
| UserId = user.Id, | |
| CreationDate = DateTime.UtcNow, | |
| ExpiryDate = DateTime.UtcNow.AddMonths(6) | |
| }; | |
| await _context.RefreshTokens.AddAsync(refreshToken); | |
| await _context.SaveChangesAsync(); | |
| return new AuthenticationResult | |
| { | |
| Success = true, | |
| Token = tokenHandler.WriteToken(token), | |
| RefreshToken = refreshToken.Token | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment