modulepackage
0.0.0-20150918093313-da5b79c3bbaf
Repository: https://github.com/nubo/jwt.git
Documentation: pkg.go.dev
# README
JWT - Helpers for Go

This package implements helpers for handling HMAC SHA-256 signed JSON Web Tokens (RFC 7519) in Go.
Usage
Producing a Token
package main
import (
"fmt"
"log"
"github.com/nubo/jwt"
)
func main() {
claims := jwt.ClaimSet{
jwt.Issuer: "example.com",
jwt.Audience: "example.com",
"lorem": "ipsum",
}
token, err := claims.Sign("secret")
if err != nil {
log.Fatal(err)
}
fmt.Println(token)
}
Consuming a Token
package main
import (
"fmt"
"log"
"github.com/nubo/jwt"
)
func main() {
rawToken := "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJleGFtcGxlLmNvbSIsImlzcyI6ImV4YW1wbGUuY29tIiwibG9yZW0iOiJpcHN1bSJ9.VhJwcvoGPhr_sY_YG6-rMNwU0YnpDSGw7jlArsnj8eA"
token, ok := jwt.ParseAndVerify(rawToken, "secret")
if !ok {
log.Fatal("Invalid token")
}
fmt.Println("Type", token.Header.Type)
fmt.Println("Algorithm", token.Header.Algorithm)
fmt.Println("Claim Set", token.ClaimSet)
fmt.Println("Signature", token.Signature)
}
Features
There is currently no plan to implement other signing algorithms than HMAC SHA-256.
- sign JWT with HMAC SHA-256
- encrypt JWT (JWE)
- parse a raw JWT to a Go struct
- verify a raw JWT
- parse and verify a raw JWT to a Go struct
- claim set
# Functions
No description provided by the author
Parse parses a JWT without verifying it's signature.
ParseAndVerify verifies a JWT signate and parses the token if ok.
No description provided by the author
No description provided by the author
Verify checks the validity of the token and verifies the integrity with HMAC SHA-256 and the given secret.
# Constants
Registered claim names are defined as constants for convenience.
Registered claim names are defined as constants for convenience.
Registered claim names are defined as constants for convenience.
Registered claim names are defined as constants for convenience.
Registered claim names are defined as constants for convenience.
Registered claim names are defined as constants for convenience.
Registered claim names are defined as constants for convenience.
# Type aliases
ClaimSet is a map for storing JWT claims.