File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -172,17 +172,17 @@ public async Task<IActionResult> RefreshToken([FromBody] RefreshTokenRequestDto
172
172
if ( string . IsNullOrEmpty ( request . Token ) )
173
173
return BadRequest ( new { message = "Token is required" } ) ;
174
174
175
- // Extract token ID (jti claim)
175
+ // Extract the token ID (jti claim)
176
176
var tokenId = _tokenService . ExtractTokenId ( request . Token ) ;
177
177
178
178
if ( string . IsNullOrEmpty ( tokenId ) )
179
179
return BadRequest ( new { message = "Invalid token" } ) ;
180
180
181
- // Check if token is blacklisted
181
+ // Check if the token is blacklisted
182
182
if ( await _tokenBlacklistRepository . IsTokenBlacklistedAsync ( tokenId ) )
183
183
return Unauthorized ( new { message = "Token has been revoked" } ) ;
184
184
185
- var principal = _tokenService . ValidateToken ( request . Token ) ;
185
+ var principal = _tokenService . ValidateTokenForRefresh ( request . Token ) ;
186
186
187
187
if ( principal == null )
188
188
return Unauthorized ( new { message = "Invalid token" } ) ;
Original file line number Diff line number Diff line change @@ -10,4 +10,5 @@ public interface ITokenService
10
10
ClaimsPrincipal ValidateToken ( string token ) ;
11
11
DateTime GetTokenExpirationTime ( string token ) ;
12
12
string ExtractTokenId ( string token ) ;
13
+ ClaimsPrincipal ValidateTokenForRefresh ( string token ) ;
13
14
}
Original file line number Diff line number Diff line change @@ -124,4 +124,23 @@ public string ExtractTokenId(string token)
124
124
125
125
return null ;
126
126
}
127
+
128
+ public ClaimsPrincipal ValidateTokenForRefresh ( string token )
129
+ {
130
+ var tokenHandler = new JwtSecurityTokenHandler ( ) ;
131
+ var key = Encoding . UTF8 . GetBytes ( _jwtSettings . SecretKey ) ;
132
+
133
+ var validationParameters = new TokenValidationParameters
134
+ {
135
+ ValidateIssuer = true ,
136
+ ValidateAudience = true ,
137
+ ValidateLifetime = false , // This is the key change - don't validate lifetime for refresh
138
+ ValidateIssuerSigningKey = true ,
139
+ ValidIssuer = _jwtSettings . Issuer ,
140
+ ValidAudience = _jwtSettings . Audience ,
141
+ IssuerSigningKey = new SymmetricSecurityKey ( key ) ,
142
+ } ;
143
+
144
+ return tokenHandler . ValidateToken ( token , validationParameters , out _ ) ;
145
+ }
127
146
}
You can’t perform that action at this time.
0 commit comments