Skip to content

nubo/jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JWT - Helpers for Go Circle CI GoDoc

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

Releases

No releases published

Packages

No packages published

Languages