mirror of https://github.com/golang-jwt/jwt.git
Community maintained clone of https://github.com/dgrijalva/jwt-go
717503fcf6
You cannot perform the not (`!`) operator on an `error`. It gives you `invalid operation: ! error`. Tested in Go Playground: http://play.golang.org/p/jhlsHoS_gc and locally on go1.2 |
||
---|---|---|
test | ||
LICENSE | ||
README.md | ||
jwt.go | ||
jwt_test.go | ||
rs256.go | ||
rs256_test.go | ||
sha256.go | ||
sha256_test.go | ||
signing_method.go |
README.md
A golang implementation of JSON Web Tokens
This library supports the parsing and verification as well as the generation and signing of JWTs. Current supported signing algorithms are RSA256 and HMAC SHA256.
This library is considered production ready. Feedback and feature requests are appreciated.
Parse and Verify
token, err := jwt.Parse(myToken, func(token *jwt.Token) ([]byte, error) {
return myLookupKey(token.Header["kid"])
})
if err == null && token.Valid {
deliverGoodness("!")
} else {
deliverUtterRejection(":(")
}
Create a token
token, _ := jwt.New(jwt.GetSigningMethod("HS256"))
token.Claims["foo"] = "bar"
token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
tokenString, err := token.SignedString(mySigningKey)
Documentation can be found here