jwt_validator

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MIT Imports: 6 Imported by: 0

README

JWT Validator

Quick Start

package main

import validator "github.com/jcarugati/jwt-validator"

const (
	token   = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiamF2aS5pbnRlcm5hbC5zZWNvcHMuY29tIl0sImNsaWVudElkIjoidmFsdWUiLCJpYXQiOjE2NjIyMTg5NjIsImlzcyI6Imphdmkuc2Vjb3BzLmNvbSJ9.bwIFsToppIdjed_kZ9xr_31P57-jdD930PPEG0sVmvI"
	jwksURL = "https://--YOUR DOMAIN----/.well-known/jwks.json"
)

func main() {
	// Create validations
	validations := validator.Validations{
		NeededScopes:            nil,
		InternalAudienceAllowed: true,
		InternalAudience:        internalAudience,
		ExternalAudienceAllowed: false,
		IssuerRequired:          true,
		Issuer:                  issuer,
	}

	// Can configure a jkws URL keyFunc if needed
	keyFunc := validator.MakeKeyFunc(jwksURL, 1000)

	// The validation process returns an error if the token could not be validated
	// In case the token is valid it'll return the claims embedded
	claims, err := validator.ValidateToken(token, keyFunc, validations)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParsingToken    = errors.New("error parsing token")
	ErrInvalidToken    = errors.New("parsed token is invalid")
	ErrInvalidClaims   = errors.New("invalid claims")
	ErrInvalidIssuer   = errors.New("invalid issuer")
	ErrInvalidAudience = errors.New("invalid audience")
	ErrInvalidScopes   = errors.New("invalid scopes")
)

Functions

func MakeKeyFunc

func MakeKeyFunc(jwksURL string, refreshInterval int64) (jwt.Keyfunc, error)

func ValidateToken

func ValidateToken(fulltoken string, keyfunc jwt.Keyfunc, validations Validations) (map[string]any, error)

Types

type Validations

type Validations struct {
	Issuer                  string
	IssuerRequired          bool
	NeededScopes            []string
	InternalAudienceAllowed bool
	InternalAudience        string
	ExternalAudienceAllowed bool
	ExternalAudience        string
}

Jump to

Keyboard shortcuts

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