jwt

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TypeJWT for signed tokens in typ header.
	TypeJWT = "JWT"
	// TypeJWE for encrypted tokens in typ header.
	TypeJWE = "JWE"
	// ContentTypeJWT for signed encrypted tokens where the encrypted token will include
	// a cty header with this value.
	ContentTypeJWT = "JWT"
)

Variables

This section is empty.

Functions

func InitializeContext

func InitializeContext(ctx context.Context) context.Context

InitializeContext adds the JWT session to the context. The new context is returned because context is immutable.

Types

type ContextKey

type ContextKey string

ContextKey defines a type to store the JWT session in context.Context.

type Session

type Session struct {
	Token                      string
	Payload                    []byte
	ContentType                string
	SignedMessage              *jws.Message
	EncryptedMessage           *jwe.Message
	SignatureAlgorithm         jwa.SignatureAlgorithm
	KeyEncryptionAlgorithm     jwa.KeyEncryptionAlgorithm
	ContentEncryptionAlgorithm jwa.ContentEncryptionAlgorithm
	PublicKey                  interface{}
	PrivateKey                 interface{}
}

Session contains the information of a JWT session.

func GetSession

func GetSession(ctx context.Context) *Session

GetSession returns the HTTP session stored in context. Note that the context should be previously initialized with InitializeContext function.

func (*Session) ConfigureContentEncryptionAlgorithm

func (s *Session) ConfigureContentEncryptionAlgorithm(ctx context.Context, alg string) error

ConfigureContentEncryptionAlgorithm configures a content encryption algorithm for the JWT (JWE).

func (*Session) ConfigureJSONPayload

func (s *Session) ConfigureJSONPayload(ctx context.Context, props map[string]interface{}) error

ConfigureJSONPayload configures the JWT payload with a map of properties.

func (*Session) ConfigureKeyEncryptionAlgorithm

func (s *Session) ConfigureKeyEncryptionAlgorithm(ctx context.Context, alg string) error

ConfigureKeyEncryptionAlgorithm configures a key encryption algorithm for the JWT (JWE).

func (*Session) ConfigurePayloadWithContentType

func (s *Session) ConfigurePayloadWithContentType(
	ctx context.Context,
	payload, contentType string,
)

ConfigurePayloadWithContentType configures the payload and the content type (cty header).

func (*Session) ConfigurePrivateKey

func (s *Session) ConfigurePrivateKey(ctx context.Context, privateKeyPEM string) error

ConfigurePrivateKey configures the private key to sign a JWT token or to decrypt a JWE token.

func (*Session) ConfigurePublicKey

func (s *Session) ConfigurePublicKey(ctx context.Context, publicKeyPEM string) error

ConfigurePublicKey configures the public key to verify the signature of a JWT token or to encrypt a JWE token.

func (*Session) ConfigureSignatureAlgorithm

func (s *Session) ConfigureSignatureAlgorithm(ctx context.Context, alg string) error

ConfigureSignatureAlgorithm configures a signature algorithm for the JWT (JWS).

func (*Session) ConfigureSymmetricKey

func (s *Session) ConfigureSymmetricKey(ctx context.Context, symmetricKey string)

ConfigureSymmetricKey configures the symmetric key. It sets this key as public and private key.

func (*Session) GenerateEncryptedJWTInContext

func (s *Session) GenerateEncryptedJWTInContext(ctx context.Context, ctxtKey string) error

GenerateEncryptedJWTInContext builds a JWT with encrypted payload and stores it in the context.

func (*Session) GenerateSignedEncryptedJWTInContext

func (s *Session) GenerateSignedEncryptedJWTInContext(ctx context.Context, ctxtKey string) error

GenerateSignedEncryptedJWTInContext builds a JWT with signed encrypted payload and stores it in the context. The payload is signed first. Then the whole JWT is considered as payload for encryption phase. The content type header (cty) of the final token is set to JWT.

func (*Session) GenerateSignedJWTInContext

func (s *Session) GenerateSignedJWTInContext(ctx context.Context, ctxtKey string) error

GenerateSignedJWTInContext builds a JWT with signed payload and stores it in the context.

func (*Session) ProcessEncryptedJWT

func (s *Session) ProcessEncryptedJWT(ctx context.Context, token string) error

ProcessEncryptedJWT reads an encrypted JWT (JWE) and stores in the session the token, encrypted message and payload. There is no validation method for encrypted tokens.

func (*Session) ProcessSignedEncryptedJWT

func (s *Session) ProcessSignedEncryptedJWT(ctx context.Context, token string) error

ProcessSignedEncryptedJWT reads a signed encrypted JWT and stores in the session the embedded signed token, the encrypted message, the signed message and the signed payload. Note that this token expects that a signed JWT token is the payload of a JWE token.

func (*Session) ProcessSignedJWT

func (s *Session) ProcessSignedJWT(ctx context.Context, token string) error

ProcessSignedJWT reads a signed JWT and stores the data in the session. This method does not validate the token; use ValidateJWT for this purpose.

func (*Session) ValidateInvalidJWT

func (s *Session) ValidateInvalidJWT(ctx context.Context, expectedError string) error

ValidateInvalidJWT checks that the token is invalid (the claims and the signature of the token). Note that JWE tokens are not validated.

func (*Session) ValidateJWT

func (s *Session) ValidateJWT(ctx context.Context) error

ValidateJWT checks that the token is valid (the claims and the signature of the token). Note that JWE tokens are not validated.

func (*Session) ValidateJWTRequirements added in v0.16.0

func (s *Session) ValidateJWTRequirements() error

func (*Session) ValidatePayloadJSONProperties

func (s *Session) ValidatePayloadJSONProperties(
	ctx context.Context,
	expectedPayload map[string]interface{},
) error

ValidatePayloadJSONProperties checks if the payload contains a map of expected properties.

type Steps

type Steps struct {
}

Steps type is responsible to initialize the JWT steps in godog framework.

func (Steps) InitializeSteps

func (s Steps) InitializeSteps(ctx context.Context, scenCtx *godog.ScenarioContext) context.Context

InitializeSteps adds JWT steps to the scenario context. It implements StepsInitializer interface. It returns a new context (context is immutable) with the JWT Context.

Jump to

Keyboard shortcuts

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