jwt

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JWT

type JWT struct {
	CookieName string        // Name of the cookie to store the JWT
	Secret     string        // Secret key used to sign the JWT
	TokenTTL   time.Duration // Token time-to-live duration
}

JWT handles JWT token creation, validation, and cookie management.

func NewJWT

func NewJWT(jwtCfg *cfg.JWTConfig) *JWT

func (*JWT) GenerateToken

func (j *JWT) GenerateToken(email string) (string, error)

GenerateToken creates a signed JWT token containing the user's email and expiration.

func (*JWT) GetCookie added in v1.1.4

func (j *JWT) GetCookie(r *http.Request) (*http.Cookie, error)

Extracts HTTP Cookie from request based on cookie name.

func (*JWT) SetCookie

func (j *JWT) SetCookie(w http.ResponseWriter, token string, domain ...string)

SetCookie sets an HTTP-only, secure cookie with the JWT token on the response writer. If a domain is provided, the cookie will be accessible across subdomains.

func (*JWT) ValidateJWT

func (j *JWT) ValidateJWT(tokenString string) (string, error)

ValidateJWT parses and validates the JWT token string. Returns the email claim if valid, or an error otherwise.

Jump to

Keyboard shortcuts

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