(username string)
| 29 | } |
| 30 | |
| 31 | func buildToken(username string) (string, error) { |
| 32 | issuedAt := time.Now() |
| 33 | expirationTime := issuedAt.Add(time.Hour) |
| 34 | |
| 35 | // Define our claims map |
| 36 | claims := jwt.MapClaims{ |
| 37 | "iat": issuedAt.Unix(), |
| 38 | "exp": expirationTime.Unix(), |
| 39 | "name": username, |
| 40 | } |
| 41 | |
| 42 | // Create a new token object, specifying signing method and the claims |
| 43 | // you would like it to contain. |
| 44 | token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) |
| 45 | |
| 46 | // Sign and get the complete encoded token as a string using the secret |
| 47 | return token.SignedString(secret) |
| 48 | } |
| 49 | |
| 50 | func keyFunc(token *jwt.Token) (any, error) { |
| 51 | return secret, nil |
no outgoing calls