auth

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	UserID string `json:"user_id"`
	// JTI is the JWT identifier, used for revocation. Tokens issued
	// before JTI rollout will have an empty JTI; callers should treat
	// an empty JTI as "not revocable" rather than as an error.
	JTI string `json:"jti"`
	// ExpiresAt is the unix timestamp from the `exp` claim, if present.
	ExpiresAt int64 `json:"exp"`

	jwt.MapClaims
}

JWT and Claims provide JWT token creation and validation.

type JWT

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

JWT and Claims provide JWT token creation and validation.

func NewJWT

func NewJWT(secret string) *JWT

NewJWT creates a new JWT instance with the given secret.

func (*JWT) Claims

func (u *JWT) Claims(tokenString string) (*Claims, error)

Claims returns the complete JWT claims object.

func (*JWT) Create

func (u *JWT) Create(userID string, ttl time.Duration) (string, error)

Create generates a signed JWT token for the given userID with the specified TTL. A fresh JTI (JWT ID) is embedded so the token can be individually revoked. Use CreateWithJTI when the caller needs to know the JTI in advance (e.g. to insert it into a revocation table later).

func (*JWT) CreateWithJTI

func (u *JWT) CreateWithJTI(userID string, ttl time.Duration) (string, string, error)

CreateWithJTI generates a signed JWT and returns both the encoded token and its JTI claim. The JTI is a ULID, lex-sortable by issue time.

func (*JWT) IsUser

func (u *JWT) IsUser(token string, userID string) bool

IsUser is a simpler version of Validate, discarding the error.

func (*JWT) UserID

func (u *JWT) UserID(token string) (string, error)

UserID retrieves the `user_id` claim from the JWT token.

func (*JWT) Validate

func (u *JWT) Validate(token string, userID string) (bool, error)

Validate checks if the JWT claims match a userID.

Jump to

Keyboard shortcuts

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