Achieves 100% XML doc coverage on non-trivial types with CS1591 enforcement via Directory.Build.props. Coverage by project: - Butter: from 6.5% to 100% (DTOs, enums, MIME types) - Lactose: from ~28% to 100% (controllers, services, repos, jobs, models) - MilkStream.Client: from ~29% to 100% (all frontend services) Uses <inheritdoc /> on repository implementations (interfaces already documented) and full <summary>/<param>/<returns> tags elsewhere. Enums include member-level docs.
33 lines
1.3 KiB
C#
33 lines
1.3 KiB
C#
using Microsoft.IdentityModel.Tokens;
|
|
using System.Security.Claims;
|
|
|
|
namespace Lactose.Utils;
|
|
|
|
/// <summary>
|
|
/// Generates JWT tokens using configurable signing credentials and a token handler.
|
|
/// </summary>
|
|
public class TokenGenerator(SigningCredentials credentials, Func<SecurityTokenDescriptor, string> handler) {
|
|
readonly TokenBuilder builder = new TokenBuilder(credentials);
|
|
|
|
/// <summary>
|
|
/// Generates a token with the specified claims and expiration time.
|
|
/// </summary>
|
|
/// <param name="claims">The claims identity to include.</param>
|
|
/// <param name="expireTime">Expiration time in minutes.</param>
|
|
/// <returns>A JWT token string.</returns>
|
|
public string Generate(ClaimsIdentity claims, int expireTime) {
|
|
builder.ExpireTime(expireTime)
|
|
.SetClaims(claims);
|
|
return builder.GenerateToken(handler);
|
|
}
|
|
/// <summary>
|
|
/// Generates a token with no additional claims and the specified expiration time.
|
|
/// </summary>
|
|
/// <param name="expireTime">Expiration time in minutes.</param>
|
|
/// <returns>A JWT token string.</returns>
|
|
public string Generate(int expireTime) {
|
|
builder.ExpireTime(expireTime);
|
|
return builder.GenerateToken(handler);
|
|
}
|
|
|
|
} |