66
77namespace SimpleAuthentication . JwtBearer ;
88
9- internal class JwtBearerService ( IOptions < JwtBearerSettings > jwtBearerSettingsOptions ) : IJwtBearerService
9+ /// <summary>
10+ /// Default implementation of <see cref="IJwtBearerService"/> that provides JWT Bearer token generation and validation.
11+ /// </summary>
12+ /// <param name="jwtBearerSettingsOptions">The JWT Bearer settings.</param>
13+ public class JwtBearerService ( IOptions < JwtBearerSettings > jwtBearerSettingsOptions ) : IJwtBearerService
1014{
11- private readonly JwtBearerSettings jwtBearerSettings = jwtBearerSettingsOptions . Value ;
15+ /// <summary>
16+ /// Gets the JWT Bearer settings used by this service.
17+ /// </summary>
18+ protected readonly JwtBearerSettings jwtBearerSettings = jwtBearerSettingsOptions . Value ;
1219
13- public Task < string > CreateTokenAsync ( string userName , IList < Claim > ? claims = null , string ? issuer = null , string ? audience = null , DateTime ? absoluteExpiration = null )
20+ /// <inheritdoc />
21+ public virtual Task < string > CreateTokenAsync ( string userName , IList < Claim > ? claims = null , string ? issuer = null , string ? audience = null , DateTime ? absoluteExpiration = null )
1422 {
1523 claims ??= [ ] ;
1624 claims . Update ( jwtBearerSettings . NameClaimType , userName ) ;
@@ -35,7 +43,8 @@ public Task<string> CreateTokenAsync(string userName, IList<Claim>? claims = nul
3543 return Task . FromResult ( token ) ;
3644 }
3745
38- public async Task < ClaimsPrincipal > ValidateTokenAsync ( string token , bool validateLifetime = true )
46+ /// <inheritdoc />
47+ public virtual async Task < ClaimsPrincipal > ValidateTokenAsync ( string token , bool validateLifetime = true )
3948 {
4049 var tokenHandler = new JsonWebTokenHandler ( ) ;
4150
@@ -71,7 +80,8 @@ public async Task<ClaimsPrincipal> ValidateTokenAsync(string token, bool validat
7180 return principal ;
7281 }
7382
74- public async Task < string > RefreshTokenAsync ( string token , bool validateLifetime , DateTime ? absoluteExpiration = null )
83+ /// <inheritdoc />
84+ public virtual async Task < string > RefreshTokenAsync ( string token , bool validateLifetime , DateTime ? absoluteExpiration = null )
7585 {
7686 var principal = await ValidateTokenAsync ( token , validateLifetime ) ;
7787 var claims = ( principal . Identity as ClaimsIdentity ) ! . Claims . ToList ( ) ;
0 commit comments