jwtoken

package
v0.0.0-...-080604a Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProtectedWithJWT

func ProtectedWithJWT[T JWTObj](token JWToken[T], onAuthenticate func(c echo.Context) error, exceptionsURI ...string) echo.MiddlewareFunc

Types

type IDRSASigner

type IDRSASigner[T JWTObj] struct {
	PrivateKey []byte `inject:"file:jwt.idrsa.priv"`
	PublicKey  []byte `inject:"file:jwt.idrsa.pub"`
}

IDRSASigner is a signer that uses an RSA private key to sign the token and an RSA public key to check the token

func (*IDRSASigner[T]) Check

func (id *IDRSASigner[T]) Check(tokenStr string) (any, error)

Check checks if the token is valid and returns the subject

func (*IDRSASigner[T]) Sign

func (id *IDRSASigner[T]) Sign(obj T, tokenExp time.Duration, refreshExp time.Duration) (JWT, error)

Sign signs the object and returns a JWT

type InvalidTokenError

type InvalidTokenError error

type JWT

type JWT struct {
	Token          string `json:"token"`
	TokenExpiresIn int64  `json:"token_exp"`

	RefreshToken     string `json:"refresh_token"`
	RefreshExpiresIn int64  `json:"refresh_exp"`
}

JWT is the struct that will be returned by the Sign method

type JWTObj

type JWTObj interface {
	GetSUB() string
	GetJIT() string
	GetSCOPES() []string
}

JWTObj is the object that will be signed

type JWTObjectInput

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

func NewJWTObjectInput

func NewJWTObjectInput(sub string, scopes []string) JWTObjectInput

func (JWTObjectInput) GetJIT

func (j JWTObjectInput) GetJIT() string

func (JWTObjectInput) GetSCOPES

func (j JWTObjectInput) GetSCOPES() []string

func (JWTObjectInput) GetSUB

func (j JWTObjectInput) GetSUB() string

type JWTSigner

type JWTSigner[T JWTObj] interface {
	Sign(T, time.Duration, time.Duration) (JWT, error)
	Check(string) (any, error)
}

JWTSigner is the interface that must be implemented by the signer

type JWToken

type JWToken[T JWTObj] struct {
	Expiration        int `inject:"property:jwt.expires_in;default:5"`
	RefreshExpiration int `inject:"property:jwt.refresh_expires_in;default:15"`
	JWTSigner         JWTSigner[T]
}

JWToken is the struct that will be injected It contains the expiration time and the signer The expiration time is in minutes

func (*JWToken[T]) Sign

func (j *JWToken[T]) Sign(obj T) (JWT, error)

type NoSubError

type NoSubError error

type NotFoundSignerType

type NotFoundSignerType error

type SECRETSigner

type SECRETSigner[T JWTObj] struct {
	Secret string `inject:"property:jwt.secret"`
}

SECRETSigner is a signer that uses a secret to sign the token

func (*SECRETSigner[T]) Check

func (id *SECRETSigner[T]) Check(tokenStr string) (any, error)

Check checks if the token is valid and returns the subject

func (*SECRETSigner[T]) Sign

func (id *SECRETSigner[T]) Sign(obj T, tokenExp time.Duration, refreshExp time.Duration) (JWT, error)

Sign signs the object and returns a JWT

type TokenExpiredError

type TokenExpiredError error

type TokenNotFound

type TokenNotFound error

Jump to

Keyboard shortcuts

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