Skip to content

Commit

Permalink
♻️ Use C# 12 collection expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
maacpiash committed Dec 21, 2024
1 parent e767e97 commit 622f445
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/Services/TokenGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,14 @@ public string GenerateAccessToken(User user)
{
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(
new[]
{
new Claim(JwtRegisteredClaimNames.Sub, user.Id.ToString()),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(ClaimTypes.NameIdentifier, user.UserName),
new Claim(ClaimTypes.Name, user.FullName),
new Claim(ClaimTypes.Email, user.Email),
new Claim(ClaimTypes.Role, user.Role),
}
),
Subject = new ClaimsIdentity([
new Claim(JwtRegisteredClaimNames.Sub, user.Id.ToString()),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(ClaimTypes.NameIdentifier, user.UserName),
new Claim(ClaimTypes.Name, user.FullName),
new Claim(ClaimTypes.Email, user.Email),
new Claim(ClaimTypes.Role, user.Role),
]),
Expires = DateTime.UtcNow.AddMinutes(15),
SigningCredentials = new SigningCredentials(
new SymmetricSecurityKey(_accessTokenSecret),
Expand All @@ -76,7 +73,7 @@ public string GenerateAccessToken(User user)
var tokenHandler = new JwtSecurityTokenHandler();
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new[] { new Claim(JwtRegisteredClaimNames.Jti, tokenId.ToString()), }),
Subject = new ClaimsIdentity([new Claim(JwtRegisteredClaimNames.Jti, tokenId.ToString())]),
Expires = DateTime.UtcNow.AddDays(1),
SigningCredentials = new SigningCredentials(
new SymmetricSecurityKey(_refreshTokenSecret),
Expand Down

0 comments on commit 622f445

Please sign in to comment.