Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidToken = errors.New("token is invalid.") ErrExpiredToken = errors.New("token has expired.") )
Different types of error returned by the VerifyToken function
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder interface { // CreateToken creates a new token for a specific username and duration CreateToken(username string, duration time.Duration, claims Claims) (string, error) // VerifyToken checks if the token is valid or not VerifyToken(token string) (*Payload, error) }
Builder is an interface for managing tokens
func NewJWTBuilder ¶
func NewJWTBuilder(secretKey string, signatureMethod jwt.SigningMethod) (Builder, error)
NewJWTBuilder creates a new JWTBuilder
func NewPasetoBuilder ¶
NewPasetoBuilder creates a new PasetoTokenBuilder
type JWTBuilder ¶
type JWTBuilder struct {
// contains filtered or unexported fields
}
JWTBuilder is a JSON Web Token builder
func (*JWTBuilder) CreateToken ¶
func (builder *JWTBuilder) CreateToken(username string, duration time.Duration, claims Claims) (string, error)
CreateToken creates a new token for a specific username and duration
func (*JWTBuilder) VerifyToken ¶
func (builder *JWTBuilder) VerifyToken(token string) (*Payload, error)
VerifyToken checks if the token is valid or not
type PasetoTokenBuilder ¶
type PasetoTokenBuilder struct {
// contains filtered or unexported fields
}
PasetoTokenBuilder is a PASETO token builder
func (*PasetoTokenBuilder) CreateToken ¶
func (builder *PasetoTokenBuilder) CreateToken(username string, duration time.Duration, claims Claims) (string, error)
CreateToken creates a new token for a specific username and duration
func (*PasetoTokenBuilder) VerifyToken ¶
func (builder *PasetoTokenBuilder) VerifyToken(token string) (*Payload, error)
VerifyToken checks if the token is valid or not
type Payload ¶
type Payload struct { ID uuid.UUID `json:"id"` Username string `json:"username"` IssuedAt time.Time `json:"issued_at"` ExpiredAt time.Time `json:"expired_at"` Claims Claims `json:"claims"` }
Payload contains the payload data of the token
func NewPayload ¶
NewPayload creates a new token payload with a specific username and duration
Click to show internal directories.
Click to hide internal directories.