Skip to content

Commit

Permalink
Refactors JWT creation
Browse files Browse the repository at this point in the history
  • Loading branch information
waldekmastykarz committed Sep 25, 2024
1 parent c8c6309 commit 391cb1b
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 44 deletions.
31 changes: 0 additions & 31 deletions dev-proxy/Jwt/Jwt.cs

This file was deleted.

2 changes: 1 addition & 1 deletion dev-proxy/Jwt/JwtCreatorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static JwtCreatorOptions Create(JwtOptions options)
Scopes = options.Scopes ?? [],
Claims = options.Claims ?? [],
NotBefore = DateTime.UtcNow,
ExpiresOn = DateTime.UtcNow.AddMinutes(options.ValidFor == 0 ? 60 : options.ValidFor)
ExpiresOn = DateTime.UtcNow.AddMinutes(options.ValidFor ?? 60)
};
}
}
2 changes: 1 addition & 1 deletion dev-proxy/Jwt/JwtOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public class JwtOptions
public IEnumerable<string>? Roles { get; set; }
public IEnumerable<string>? Scopes { get; set; }
public Dictionary<string, string>? Claims { get; set; }
public double ValidFor { get; set; }
public double? ValidFor { get; set; }
}
12 changes: 1 addition & 11 deletions dev-proxy/Jwt/JwtTokenGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ internal static string CreateToken(JwtOptions jwtOptions)
);

var jwtToken = jwtIssuer.CreateSecurityToken(options);

var jwt = Jwt.Create(
options.Scheme,
jwtToken,
new JwtSecurityTokenHandler().WriteToken(jwtToken),
options.Scopes,
options.Roles,
options.Claims
);

return jwt.Token;
return new JwtSecurityTokenHandler().WriteToken(jwtToken);
}
}

0 comments on commit 391cb1b

Please sign in to comment.