jwt/README.md

30 lines
948 B
Markdown
Raw Normal View History

2012-04-18 22:33:12 +04:00
A [golang](http://www.golang.org) implementation of [JSON Web Tokens](http://self-issued.info/docs/draft-jones-json-web-token.html)
2014-01-29 22:08:31 +04:00
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.
2012-07-07 03:27:42 +04:00
## Parse and Verify
```go
token, err := jwt.Parse(myToken, func(token *jwt.Token) ([]byte, error) {
return myLookupKey(token.Header["kid"])
2012-07-07 03:27:42 +04:00
})
2014-04-10 01:26:16 +04:00
if err == nil && token.Valid {
2012-07-07 03:27:42 +04:00
deliverGoodness("!")
} else {
deliverUtterRejection(":(")
}
```
2012-07-07 03:27:42 +04:00
## Create a token
```go
token := jwt.New(jwt.GetSigningMethod("HS256"))
2012-07-07 03:27:42 +04:00
token.Claims["foo"] = "bar"
token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
2014-01-29 22:08:31 +04:00
tokenString, err := token.SignedString(mySigningKey)
```
Documentation can be found [here](http://godoc.org/github.com/dgrijalva/jwt-go)