jwks

package
v0.0.0-...-f839e32 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyJWK = fmt.Errorf("specified JWK is empty")
)

Functions

This section is empty.

Types

type JWK

type JWK struct {
	// Alg specifies cryptographic algorithm used with the key. Ex.: "RS256"
	Alg string `json:"alg" yaml:"alg"`
	// Kty specifies family of cryptographic algorithms used with the key. Ex.: "RSA"
	Kty string `json:"kty" yaml:"kty"`
	// Use specifies how the key was meant to be used; Ex.: "sig" represents the signature.
	Use string `json:"use" yaml:"use"`
	// N specifies modulus for the RSA public key. Ex.: "vY07WxvavajnrJRe6...."
	N string `json:"n" yaml:"n"`
	// E specifies exponent for the RSA public key. Ex.: "AQAB"
	E string `json:"e" yaml:"e"`
	// Kid specifies identifier of the key. Ex.: "M_XXXX-n"
	Kid string `json:"kid" yaml:"kid"`
	// X5t specifies thumbprint of the x.509 cert (SHA-1 thumbprint). Ex.: "kXXNB-yYYYYYt"
	X5t string `json:"x5t" yaml:"x5t"`
	// X5c specifies x.509 certificate chain.
	// X5c[0] is the certificate to use for token verification
	// X5c[1:] [OPTIONAL, not necessary to be included] can be used to verify X5c[0].
	X5c []string `json:"x5c" yaml:"x5c"`

	File string `json:"file,omitempty" yaml:"file,omitempty"`
	Data string `json:"data,omitempty" yaml:"data,omitempty"`

	// PublicKey is a parsed public key extracted from X5c chain
	PublicKey *rsa.PublicKey
}

JWK specifies one JSON Web Key

func NewJWKFromBytes

func NewJWKFromBytes(bytes []byte) (*JWK, error)

NewJWKFromBytes

func NewJWKFromFile

func NewJWKFromFile(filename string) (*JWK, error)

NewJWKFromFile

func NewJWKFromString

func NewJWKFromString(cert string) (*JWK, error)

NewJWKFromString

func (*JWK) FillNonEmptyFrom

func (jwk *JWK) FillNonEmptyFrom(src *JWK) *JWK

FillNonEmptyFrom

func (*JWK) Parse

func (jwk *JWK) Parse() error

Parse

func (*JWK) ReadIn

func (jwk *JWK) ReadIn() *JWK

ReadIn

func (*JWK) String

func (jwk *JWK) String() string

String

type JWKS

type JWKS struct {
	// Keys is a set of keys - main part of the JWKS
	Keys []*JWK `json:"keys,omitempty" yaml:"keys,omitempty"`

	// File specifies what JSON-containing file to read keys (key set) from.
	File string `json:"file,omitempty" yaml:"file,omitempty"`
	// URL specifies what JSON-containing url to read keys (key set) from.
	URL string `json:"url,omitempty" yaml:"url,omitempty"`
	// Data specifies JSON-string with keys (key set) to be parsed.
	Data string `json:"data,omitempty" yaml:"data,omitempty"`
}

JWKS specifies JSON Web Key Set (JWKS). JWKS is a set of public keys used to verify JWT issued by authorization server See more for details: https://auth0.com/docs/security/tokens/json-web-tokens/json-web-key-sets

func New

func New() *JWKS

New creates new empty JWKS

func NewFromBytes

func NewFromBytes(json []byte) (*JWKS, error)

NewFromBytes creates new JWKS from JSON bytes

func NewFromFile

func NewFromFile(filename string) (*JWKS, error)

NewFromFile creates new JWKS from file with JSON

func NewFromReader

func NewFromReader(jsonJWKS io.Reader) (*JWKS, error)

NewFromReader creates new JWKS from reader which providers JSON

func NewFromString

func NewFromString(jsonJWKS string) (*JWKS, error)

NewFromString creates new JWKS from JSON string

func NewFromURL

func NewFromURL(url string) (*JWKS, error)

NewFromURL creates new JWKS from URL which providers JSON

func (*JWKS) Append

func (jwks *JWKS) Append(jwk ...*JWK) *JWKS

Append appends JWK to the set

func (*JWKS) GetDefaultKey

func (jwks *JWKS) GetDefaultKey() *JWK

GetDefaultKey gets default key

func (*JWKS) GetVerificationPublicKey

func (jwks *JWKS) GetVerificationPublicKey(token *jwt.Token, fallbackToDefault bool) (*rsa.PublicKey, error)

GetVerificationPublicKey searches for cert specified in token's header

func (*JWKS) ReadIn

func (jwks *JWKS) ReadIn() *JWKS

ReadIn reads keys from all specified sources (file, url, string) and appends these keys to the set

func (*JWKS) String

func (jwks *JWKS) String() string

String return string form of the keys set

Jump to

Keyboard shortcuts

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