NewJWT generates and returns new HS256 signed JWT.
(payload jwt.MapClaims, signingKey string, duration time.Duration)
| 44 | |
| 45 | // NewJWT generates and returns new HS256 signed JWT. |
| 46 | func NewJWT(payload jwt.MapClaims, signingKey string, duration time.Duration) (string, error) { |
| 47 | claims := jwt.MapClaims{ |
| 48 | // @todo consider with the refactoring to either remove the |
| 49 | // duration argument or make it always take precedence? |
| 50 | "exp": time.Now().Add(duration).Unix(), |
| 51 | } |
| 52 | |
| 53 | for k, v := range payload { |
| 54 | claims[k] = v |
| 55 | } |
| 56 | |
| 57 | return jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(signingKey)) |
| 58 | } |
searching dependent graphs…