fixed authorization

This commit is contained in:
2025-12-09 15:42:35 +08:00
parent ca49e8e24b
commit 5743dbf22d
15 changed files with 1936 additions and 62 deletions
+6 -9
View File
@@ -31,10 +31,7 @@ var (
jwtSecretError error
// Pre-allocate error messages to avoid repeated allocations
errInvalidAuthFormat = "invalid authorization header format"
errInvalidToken = "Invalid token"
errExpiredToken = "Invalid or expired token"
errInvalidClaims = "Invalid token claims"
errExpiredToken = "Invalid or expired token"
)
// Initialize JWT secret once
@@ -100,11 +97,11 @@ func checkTokenCache(tokenString string) (*models.Claims, bool) {
}
// removeExpiredCacheEntry removes a single expired token from cache
func removeExpiredCacheEntry(tokenString string) {
tokenCacheMutex.Lock()
defer tokenCacheMutex.Unlock()
delete(tokenCache, tokenString)
}
// func removeExpiredCacheEntry(tokenString string) {
// tokenCacheMutex.Lock()
// defer tokenCacheMutex.Unlock()
// delete(tokenCache, tokenString)
// }
// parseAndValidateToken parses JWT token and validates it
func parseAndValidateToken(tokenString string) (*models.Claims, error) {