Help us shape the future of Go! Take the 2026 Go Developer Survey

token

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package token signs and parses the HS256 JSON Web Tokens the server hands out: the session tokens of package usersession and billing's order event tickets. It checks only the signature and the expiry; what a token grants is for the package that issued it to decide.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJwtToken

func NewJwtToken(secretKey string, iat, seconds int64, opt ...Option) (string, error)

NewJwtToken Generate and return jwt token with given data.

func ParseJwtToken

func ParseJwtToken(tokenString, secretKey string) (jwt.MapClaims, error)

ParseJwtToken parses a token this package issued and returns its claims. Only HS256 is accepted, the algorithm NewJwtToken signs with, so a token declaring another algorithm ("none", an RSA one) is refused before its signature is looked at; and an expiry is required, since every token this package issues carries one, so a forged token cannot live forever by leaving it out.

Types

type Option

type Option struct {
	Key string
	Val any
}

Option jwt additional data

func WithOption

func WithOption(key string, val any) Option

WithOption returns Option with key-value pairs

Jump to

Keyboard shortcuts

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