From 15b4825280850476bfd071ac87e8af46b8eda4f1 Mon Sep 17 00:00:00 2001 From: Jamie Stackhouse Date: Mon, 20 Jul 2015 13:25:55 -0300 Subject: [PATCH] Add example to migration showing new usage of Parse(WithClaims) --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index bda890b..7907c0b 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,21 @@ and includes a few helper functions for verifying the claims defined [here](http On the other end of usage all of the `jwt.Parse` and friends got a `WithClaims` suffix added to them. +```go + token, err := jwt.Parse(token, keyFunc) + claims := token.Claims.(jwt.MapClaim) + //like you used to.. + claims["foo"] + claims["bar"] +``` + +New method usage: +```go + token, err := jwt.ParseWithClaims(token, keyFunc, &jwt.StandardClaims{}) + claims := token.Claims.(jwt.StandardClaims) + fmt.Println(claims.IssuedAt) +``` + ## What the heck is a JWT? In short, it's a signed JSON object that does something useful (for example, authentication). It's commonly used for `Bearer` tokens in Oauth 2. A token is made of three parts, separated by `.`'s. The first two parts are JSON objects, that have been [base64url](http://tools.ietf.org/html/rfc4648) encoded. The last part is the signature, encoded the same way.