jwt

package
v1.2.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Email = "email"
	Exp   = "exp"
	Alg   = "alg"
)

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) RemoveCookie added in v1.1.5

func (j *JWT) RemoveCookie(w http.ResponseWriter, secure bool, domain ...string)

RemoveCookie removes the JWT cookie by setting an expired Set-Cookie header.

func (*JWT) SetCookie

func (j *JWT) SetCookie(w http.ResponseWriter, token string, secure bool, 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