jwks

package module
v0.0.0-...-858805f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

README

What?

Go implementation of jwks-rsa

How does it work?

  • Pulls modulus
  • Creates []Public Keys
  • Verifies tokens based Audience and []Public Keys

Why?

  • Same reason the node one exists. The Firebase Admin SDK is clunky just for verifying tokens. Also, versioning becomes a pain.

Basic Example

import (
	...
	"github.com/dchahla/jwks"
  	"github.com/gorilla/mux"
	"github.com/joho/godotenv"
	"github.com/rs/cors"

)

router := mux.NewRouter()
router.Use(cors.New(cors.Options{
	AllowedHeaders: []string{"Authorization", "Content-Type"},
}).Handler)

//  define audience (string)
AUDIENCE := os.Getenv("AUDIENCE")

//  cache public keys
keys := jwks.InitKeySet() 

//  set up middleware to use audience and keys
middleware := jwks.Verify(AUDIENCE, "RS256", &keys)

//  release the hounds! (apply the middleware.)
router.PathPrefix("/api/v1/app/delegation/groups").Handler(middleware(http.HandlerFunc(getGroupsHandler)))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartKeySetUpdateRoutine

func StartKeySetUpdateRoutine(keys *KeySet)

Types

type FirebaseToken

type FirebaseToken struct {
	Audience string `json:"aud"`
	AuthTime int64  `json:"auth_time"`
	Expiry   int64  `json:"exp"`
	Firebase struct {
		Identities     map[string]interface{} `json:"identities"`
		SignInProvider string                 `json:"sign_in_provider"`
	} `json:"firebase"`
	IssuedAt   int64  `json:"iat"`
	Issuer     string `json:"iss"`
	ProviderID string `json:"provider_id"`
	Subject    string `json:"sub"`
	UserID     string `json:"user_id"`
}

type KeySet

type KeySet struct {
	Primary   []byte
	Fallbacks [][]byte
}

func InitKeySet

func InitKeySet() KeySet

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

func Verify

func Verify(audience string, algorithm string, keys *KeySet) MiddlewareFunc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL