token

package
v0.0.0-...-f47b430 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrInvalidKeySize indicates error for invalidate token key.
	// The chacha20poly1305 algo requires a 32 byte or character key.
	ErrInvalidKeySize = "invalid key size: must be exactly %d characters"

	// Issuer indicates the creator of the token
	Issuer = "coderaOJ.com"
)
View Source
const (
	// ErrInvalidToken indicates the error of token invalidation
	ErrInvalidToken = "token is invalid: %v"

	// ErrExpiredToken indicated the error of token expiration
	ErrExpiredToken = "token is expired"
)

Variables

This section is empty.

Functions

func NewPasetoPayload

func NewPasetoPayload(claimsInfo *ClaimsInfo, duration time.Duration) (*paseto.JSONToken, error)

NewPasetoPayload creates Payload instance for specific username and duration

Types

type ClaimsInfo

type ClaimsInfo struct {
	Username  string
	ClientIP  string
	UserAgent string
}

ClaimsInfo holds the claims information for a user

type PasetoToken

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

PasetoToken describes a paseto token

func (*PasetoToken) CreateToken

func (pt *PasetoToken) CreateToken(claimsInfo *ClaimsInfo, duration time.Duration) (*TokenInfo, error)

CreateToken creates a new token for a specific username and duration

func (*PasetoToken) VerifyToken

func (pt *PasetoToken) VerifyToken(token string) (*paseto.JSONToken, error)

VerifyToken verifies if the given token is valid or not. And also returns the payload if the token is valid.

type TokenInfo

type TokenInfo struct {
	Token   string
	Payload *paseto.JSONToken
}

TokenInfo holds the information related to a token

type TokenManager

type TokenManager interface {
	CreateToken(claimsInfo *ClaimsInfo, duration time.Duration) (*TokenInfo, error)
	VerifyToken(token string) (*paseto.JSONToken, error)
}

TokenManager is the interface for managing tokens

func NewPasetoToken

func NewPasetoToken(symmetricKey []byte) (TokenManager, error)

NewPasetoToken creates PasetoToken instance

Jump to

Keyboard shortcuts

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