Skip to content

Instantly share code, notes, and snippets.

@sle-c
Created May 31, 2019 20:22
Show Gist options
  • Save sle-c/66b1a68edde248249375aee553734975 to your computer and use it in GitHub Desktop.
Save sle-c/66b1a68edde248249375aee553734975 to your computer and use it in GitHub Desktop.
Encode things to JWT Token
package goliauth
import (
"fmt"
jwt "github.com/dgrijalva/jwt-go"
)
// EncodeJWT serialize data into a jwt token using a secret
// This secret must match with the client's secret who's generating the token
func EncodeJWT(secretKey string, claims Claims) (string, error) {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
secret := []byte(secretKey)
tokenString, err := token.SignedString(secret)
if err != nil {
return "", err
}
return tokenString, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment