jwt

package
v0.0.0-...-bd860cc Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TypeJWT defines JWT type.
	TypeJWT = "JWT"
	// TypeSDJWT defines SD-JWT type v5+.
	TypeSDJWT = "SD-JWT"

	// AlgorithmNone used to indicate unsecured JWT.
	AlgorithmNone = "none"
)

Variables

This section is empty.

Functions

func CheckHeaders

func CheckHeaders(headers map[string]interface{}) error

CheckHeaders checks jwt headers.

func CheckProof

func CheckProof(jwtSerialized string, proofChecker ProofChecker,
	expectedProofIssuer *string, detachedPayload []byte) error

CheckProof checks that jwt have correct signature.

func IsJWS

func IsJWS(s string) bool

IsJWS checks if JWT is a JWS of valid structure.

func IsJWTUnsecured

func IsJWTUnsecured(s string) bool

IsJWTUnsecured checks if JWT is an unsecured JWT of valid structure.

func PayloadToMap

func PayloadToMap(i interface{}) (map[string]interface{}, error)

PayloadToMap transforms interface to map.

Types

type Claims

type Claims jwt.Claims

Claims defines JSON Web Token Claims (https://tools.ietf.org/html/rfc7519#section-4)

type JSONWebToken

type JSONWebToken struct {
	Headers jose.Headers

	Payload map[string]interface{}
	// contains filtered or unexported fields
}

JSONWebToken defines JSON Web Token (https://tools.ietf.org/html/rfc7519)

func NewJoseSigned

func NewJoseSigned(claims interface{}, headers jose.Headers, signer jose.Signer) (*JSONWebToken, error)

NewJoseSigned creates new signed JSON Web Token based on input claims.

func NewSigned

func NewSigned(claims interface{}, signParams SignParameters, signer ProofCreator) (*JSONWebToken, error)

NewSigned creates new signed JSON Web Token based on input claims.

func NewUnsecured

func NewUnsecured(claims interface{}) (*JSONWebToken, error)

NewUnsecured creates new unsecured JSON Web Token based on input claims.

func Parse

func Parse(jwtSerialized string, opts ...ParseOpt) (*JSONWebToken, []byte, error)

Parse parses input JWT in serialized form into JSON Web Token.

func ParseAndCheckProof

func ParseAndCheckProof(jwtSerialized string,
	proofChecker ProofChecker, checkIssuer bool, opts ...ParseOpt) (*JSONWebToken, []byte, error)

ParseAndCheckProof parses input JWT in serialized form into JSON Web Token and check signature proof. if checkIssuer set to true, will check if issuer set by "iss" own key set by "kid" header.

func (*JSONWebToken) DecodeClaims

func (j *JSONWebToken) DecodeClaims(c interface{}) error

DecodeClaims fills input c with claims of a token.

func (*JSONWebToken) LookupStringHeader

func (j *JSONWebToken) LookupStringHeader(name string) string

LookupStringHeader makes look up of particular header with string value.

func (*JSONWebToken) Serialize

func (j *JSONWebToken) Serialize(detached bool) (string, error)

Serialize makes (compact) serialization of token.

type JoseSigner

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

JoseSigner implement jose.proofCreator interface.

func NewJOSESigner

func NewJOSESigner(params SignParameters, signer ProofCreator) (*JoseSigner, error)

NewJOSESigner wraps ProofCreator into jose signer.

func (JoseSigner) Headers

func (s JoseSigner) Headers() jose.Headers

Headers returns headers.

func (JoseSigner) Sign

func (s JoseSigner) Sign(data []byte) ([]byte, error)

Sign returns signature.

type ParseOpt

type ParseOpt func(opts *parseOpts)

ParseOpt is the JWT Parser option.

func DecodeClaimsTo

func DecodeClaimsTo(decodeDestination interface{}) ParseOpt

DecodeClaimsTo if set claims will be decoded into object pointed by decodeDestination argument.

func WithIgnoreClaimsMapDecoding

func WithIgnoreClaimsMapDecoding(ignoreClaimsMapDecoding bool) ParseOpt

WithIgnoreClaimsMapDecoding option is for ignore decoding claims into .Payload map[string]interface. Decoding to map[string]interface is pretty expensive, so this option can be used for performance critical operations.

func WithJWTDetachedPayload

func WithJWTDetachedPayload(payload []byte) ParseOpt

WithJWTDetachedPayload option is for definition of JWT detached payload.

type ProofChecker

type ProofChecker interface {
	// CheckJWTProof check jwt proof.
	CheckJWTProof(headers jose.Headers, expectedProofIssuer string, msg, signature []byte) error
}

ProofChecker used to check proof of jwt vc.

type ProofCreator

type ProofCreator interface {
	SignJWT(params SignParameters, data []byte) ([]byte, error)
	CreateJWTHeaders(params SignParameters) (jose.Headers, error)
}

ProofCreator defines signer interface which is used to sign VC JWT.

type SignParameters

type SignParameters struct {
	KeyID             string
	JWTAlg            string
	AdditionalHeaders jose.Headers
}

SignParameters contains parameters of signing for jwt vc.

Jump to

Keyboard shortcuts

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