jwt

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 7 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"`
	Nonce    string `json:"nonce"`
}

Claims are the fields stored in a JWT.

type Service added in v0.2.0

type Service struct {
	Secret []byte
	Nonces nonce.Repository
}

Service handles common JWT manipulation.

func (*Service) GenerateToken added in v0.2.0

func (s *Service) GenerateToken(
	ctx context.Context,
	userID string,
	userName string,
	long bool,
) (claims *Claims, signed string)

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 (*Service) VerifyToken added in v0.2.0

func (s *Service) VerifyToken(ctx context.Context, 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