generateToken creates a JWT token for testing purposes. In a real application, this would be handled by your authentication service.
(userID string, scopes []string, expiresIn time.Duration)
| 68 | // generateToken creates a JWT token for testing purposes. |
| 69 | // In a real application, this would be handled by your authentication service. |
| 70 | func generateToken(userID string, scopes []string, expiresIn time.Duration) (string, error) { |
| 71 | // Create JWT claims with user information and scopes. |
| 72 | claims := JWTClaims{ |
| 73 | UserID: userID, |
| 74 | Scopes: scopes, |
| 75 | RegisteredClaims: jwt.RegisteredClaims{ |
| 76 | ExpiresAt: jwt.NewNumericDate(time.Now().Add(expiresIn)), // Token expiration |
| 77 | IssuedAt: jwt.NewNumericDate(time.Now()), // Token issuance time |
| 78 | NotBefore: jwt.NewNumericDate(time.Now()), // Token validity start time |
| 79 | }, |
| 80 | } |
| 81 | |
| 82 | // Create and sign the JWT token. |
| 83 | token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) |
| 84 | return token.SignedString(jwtSecret) |
| 85 | } |
| 86 | |
| 87 | // verifyJWT verifies JWT tokens and returns TokenInfo for the auth middleware. |
| 88 | // This function implements the TokenVerifier interface required by auth.RequireBearerToken. |
no outgoing calls
no test coverage detected
searching dependent graphs…