/jwt

Golang implementation of JSON Web Tokens (JWT)

Primary LanguageGoMIT LicenseMIT

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 == nil && 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