jwt

package
v0.0.0-...-4044be6 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Instance

type Instance struct {
	SigningMethod         jwt.SigningMethod
	PublicKey             ed25519.PublicKey
	PrivateKey            ed25519.PrivateKey
	HeaderLen             int
	ExpirationTimeInHours int
}

func GetJwtInstance

func GetJwtInstance() *Instance

func NewInstance

func NewInstance(options ...InstanceOption) *Instance

func NewJWTInstance

func NewJWTInstance(headerLen, expirationTime int,
	publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey,
) *Instance

NewJWTInstance return a new JwtInstance with the given parameters.

func (Instance) CalculateExpirationTime

func (instance Instance) CalculateExpirationTime() *jwt.NumericDate

CalculateExpirationTime returns the expiration time.

func (Instance) GenerateToken

func (instance Instance) GenerateToken(_ context.Context, userID int32) (string, error)

GenerateToken generates a jwt token from a user id and returns the token and an error

It's signing method is defined in utils.JwtSigningMethod It's expiration time is defined in utils.GetExpirationTime It's secret key is defined in the environment variable SECRET_KEY see: utils/config.go for more information

func (Instance) GetConnectedUserID

func (instance Instance) GetConnectedUserID(ctx context.Context, tokenString string) (int32, error)

GetConnectedUserID gets the user id from a jwt token.

func (Instance) GetExpirationTime

func (Instance) GetExpirationTime(token *jwt.Token) int64

func (Instance) GetToken

func (instance Instance) GetToken(_ context.Context, token string) (*jwt.Token, error)

GetToken gets a jwt.Token token from a string and returns the jwt.Token and an error.

func (*Instance) SetJwt

func (instance *Instance) SetJwt()

func (Instance) VerifyToken

func (Instance) VerifyToken(token *jwt.Token) (int32, error)

VerifyToken verifies a jwt token and returns the user id and an error.

type InstanceOption

type InstanceOption func(*Instance)

func WithExpirationTime

func WithExpirationTime(expirationTimeInHours int) InstanceOption

func WithHeaderLen

func WithHeaderLen(headerLen int) InstanceOption

func WithKeys

func WithKeys(publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey) InstanceOption

func WithSigningMethod

func WithSigningMethod(method jwt.SigningMethod) InstanceOption

Jump to

Keyboard shortcuts

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