1
1
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart' ;
2
+ import 'package:ht_api/src/config/environment_config.dart' ;
2
3
import 'package:ht_api/src/services/auth_token_service.dart' ;
3
4
import 'package:ht_api/src/services/token_blacklist_service.dart' ;
4
5
import 'package:ht_data_repository/ht_data_repository.dart' ;
@@ -33,11 +34,6 @@ class JwtAuthTokenService implements AuthTokenService {
33
34
34
35
// --- Configuration ---
35
36
36
- // WARNING: Hardcoding secrets is insecure. Use environment variables
37
- // or a proper secrets management solution in production.
38
- static const String _secretKey =
39
- 'your-very-hardcoded-super-secret-key-replace-this-in-prod' ;
40
-
41
37
// Define token issuer and default expiry duration
42
38
static const String _issuer = 'http://localhost:8080' ;
43
39
static const Duration _tokenExpiryDuration = Duration (hours: 1 );
@@ -71,7 +67,7 @@ class JwtAuthTokenService implements AuthTokenService {
71
67
72
68
// Sign the token using HMAC-SHA256
73
69
final token = jwt.sign (
74
- SecretKey (_secretKey ),
70
+ SecretKey (EnvironmentConfig .jwtSecretKey ),
75
71
algorithm: JWTAlgorithm .HS256 ,
76
72
expiresIn: _tokenExpiryDuration, // Redundant but safe
77
73
);
@@ -93,7 +89,7 @@ class JwtAuthTokenService implements AuthTokenService {
93
89
try {
94
90
// Verify the token's signature and expiry
95
91
_log.finer ('[validateToken] Verifying token signature and expiry...' );
96
- final jwt = JWT .verify (token, SecretKey (_secretKey ));
92
+ final jwt = JWT .verify (token, SecretKey (EnvironmentConfig .jwtSecretKey ));
97
93
_log.finer ('[validateToken] Token verified. Payload: ${jwt .payload }' );
98
94
99
95
// --- Blacklist Check ---
@@ -216,7 +212,7 @@ class JwtAuthTokenService implements AuthTokenService {
216
212
_log.finer ('[invalidateToken] Verifying signature (ignoring expiry)...' );
217
213
final jwt = JWT .verify (
218
214
token,
219
- SecretKey (_secretKey ),
215
+ SecretKey (EnvironmentConfig .jwtSecretKey ),
220
216
checkExpiresIn: false , // IMPORTANT: Don't fail if expired here
221
217
checkHeaderType: true , // Keep other standard checks
222
218
);
0 commit comments