jwtvalid

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

README

Module jwt_valid

{
    "pem_keypath": "",
    "secret": "",
    "has_claim": "" "",
    "startswith_claim": "" "",
    "clockskew": "",
    "fail_header": "" ""
}

Description


An HTTP middleware module that validates a JWT using the given query parameter access_token or Authorization header.

It will skip validation if the current HTTP request is an OPTIONS call

Validation can be performed using a given secret OR a public key provided in a PEM formatted file

Field List


pem_keypath

Path to PEM formatted public key file

secret

A text string containing a secret

has_claim

Optional additional validation to ensure given claims contain given values

Expressed as [name] [value] pairs

This field can repeat

startswith_claim

Optional additional validation to ensure given claims starts with the given values

Expressed as [name] [value] pairs

This field can repeat

clockskew

Optional time offset to be used to extend the token expiry validation range

Expressed as a string suitable for https://golang.org/pkg/time/#ParseDuration

fail_header

Optional additional HTTP headers to add to any failed response

Expressed as [name] [value] pairs

Example


jwt_valid {
  secret "MyBigSecret"
  has_claim foo bar
  startswith_claim foo ba
  has_claim hello world
  clockskew "10m"
  fail_header hello world
}
Build Instructions

The Makefile is used for all build operations. The file envfile is used for local environment customisations.

Please refer to https://caddyserver.com/docs/extending-caddy for details of configuring your environment and the use of xcaddy.


The current version of Caddy Server specified in the envfile is 2.6.2


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JwtValid

type JwtValid struct {
	KeyPath          string            `json:"pemkeypath,omitempty"`
	Secret           string            `json:"secret,omitempty"`
	Claims           map[string]string `json:"hasclaims,omitempty"`
	StartsWithClaims map[string]string `json:"startswithclaims,omitempty"`
	Headers          map[string]string `json:"failheaders,omitempty"`
	ClockSkewSeconds time.Duration     `json:"clockskew,omitempty"`
	// contains filtered or unexported fields
}

func (JwtValid) CaddyModule

func (JwtValid) CaddyModule() caddy.ModuleInfo

func (*JwtValid) Provision

func (jtv *JwtValid) Provision(ctx caddy.Context) error

func (JwtValid) ServeHTTP

func (jtv JwtValid) ServeHTTP(resp http.ResponseWriter, req *http.Request, next caddyhttp.Handler) error

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

func NewValidator

func NewValidator(pemFilePath string, secret string, clockSkew time.Duration, hasClaims *map[string]string, startsWithClaims *map[string]string, logger *zap.Logger) *Validator

func (Validator) Valid

func (v Validator) Valid(token string) (bool, error)

Jump to

Keyboard shortcuts

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