jwt

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package jwt defines all the methods for JWT manipulation.

Index

Constants

View Source
const ExpiresDuration = 24 * time.Hour

ExpiresDuration is the duration when a user session expires.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims
	UserID   string `json:"user_id"`
	UserName string `json:"user_name"`
}

Claims are the fields stored in a JWT.

type Secret

type Secret []byte

Secret is a HMAC JWT secret used for signing.

func (Secret) GenerateToken

func (s Secret) GenerateToken(userID string, userName string) (string, error)

GenerateToken creates a JWT session token which stores the user identity.

The returned token is signed with the JWT secret, meaning it cannot be falsified.

func (Secret) VerifyToken

func (s Secret) VerifyToken(tokenString string) (*Claims, error)

VerifyToken checks if the token signature is valid compared to the JWT secret.

Jump to

Keyboard shortcuts

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