Skip to content
/ jwk-go Public

Fetch and cache JWT public keys from JSON Web Key stores

Notifications You must be signed in to change notification settings

Serjlee/jwk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jwk.go

Package jwk offer useful functions to handle, fetch and cache JWT public keys from a public JSON Web Key store (IETF RFC 7517, see: https://tools.ietf.org/html/rfc7517)

This package does not currently support the whole standard, but just the slim subset needed for working with the Auth0 Json Web Key Stores: https://auth0.com/docs/jwks

Example

package main

import (
 "fmt"
 "log"

 "github.com/serjlee/jwk.go"
 "github.com/go-jose/go-jose/v3/jwt"
)

 func main() {
  token := "your.jwt.token"
  t, err := jwt.ParseSigned(token)
  if err != nil {
   log.Fatal(err)
  }
  keys := jwk.JSONWebKeys{
   JWKURL: "https://{your-auth0-domain}/.well-known/jwks.json",
  }
  key, err := keys.GetKey(t.Headers[0].KeyID)
  if err != nil {
   log.Fatal(err)
  }
  // that's your public key
  fmt.Println(string(key))
  // you can use an helper function to get it with PEM headers
  fmt.Println(key.PEM())
 }

About

Fetch and cache JWT public keys from JSON Web Key stores

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages