auth

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidToken = errors.New("invalid or expired token")

ErrInvalidToken represents error when token is invalid or expired

Functions

This section is empty.

Types

type Auth

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

Auth represents dependencies for auth methods

func New

func New(algorithm string, privateKey *rsa.PrivateKey, claimsIssuer string, accessTokenTTL, refreshTokenTTL time.Duration) (*Auth, error)

New constructs Auth instance

func (*Auth) CreateUserClaims

func (a *Auth) CreateUserClaims(user model.User) jwt.Claims

CreateUserClaims creates claims for user

func (*Auth) GenerateRefreshToken

func (a *Auth) GenerateRefreshToken() (string, time.Time, error)

GenerateRefreshToken returns generated random refresh token and its expiration date

func (*Auth) GenerateToken

func (a *Auth) GenerateToken(claims jwt.Claims) (string, error)

GenerateToken generates JWT token with claims

func (*Auth) GetClaimsFromToken

func (a *Auth) GetClaimsFromToken(tokenStr string) (Claims, error)

GetClaimsFromToken validates token and returns claims from it

type Claims

type Claims struct {
	jwt.RegisteredClaims
	UserID   string `json:"user_id"`
	UserRole string `json:"user_role,omitempty"`
	Username string `json:"username,omitempty"`
	Name     string `json:"name,omitempty"`
	// VerificationRequired - represents requirement to verify email (true = not verified, false = verified or does not require verification)
	VerificationRequired bool `json:"vrf_required"`
}

Claims represent jwt claims

type UnsubscribeTokenGenerator

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

UnsubscribeTokenGenerator generates and validates unsubscribe tokens

func NewUnsubscribeTokenGenerator

func NewUnsubscribeTokenGenerator(secretKey []byte) *UnsubscribeTokenGenerator

NewUnsubscribeTokenGenerator creates a new token generator with the given secret

func (*UnsubscribeTokenGenerator) GenerateToken

func (g *UnsubscribeTokenGenerator) GenerateToken(email string, expiresAt time.Time) string

GenerateToken creates an unsubscribe token for the given email and expiry

func (*UnsubscribeTokenGenerator) ValidateToken

func (g *UnsubscribeTokenGenerator) ValidateToken(token string) (string, error)

ValidateToken validates an unsubscribe token and returns the email if valid

Jump to

Keyboard shortcuts

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