Created
May 31, 2019 20:22
-
-
Save sle-c/66b1a68edde248249375aee553734975 to your computer and use it in GitHub Desktop.
Encode things to JWT Token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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