token

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package token manipulates and inspects tokens for the authentication cases (FR-CASE-10) and the expiry check (FR-AUTH-06). It never verifies signatures and needs no key.

Index

Constants

View Source
const TruncateLen = 100

TruncateLen is how many characters of the real token Truncate keeps.

Variables

This section is empty.

Functions

func Expiry

func Expiry(tok string) (exp time.Time, ok bool)

Expiry returns the "exp" claim of a JWT. ok is false for other tokens or tokens without "exp". The token is decoded, not verified.

func IsJWT

func IsJWT(tok string) bool

IsJWT reports whether tok looks like a JWS in compact form (header.payload.signature) with a decodable signature.

func Tamper

func Tamper(tok string) string

Tamper returns a copy of tok that must be rejected by any server that validates tokens. It differs from tok as much as possible while keeping its form, so a cache or proxy keyed on parts of the token cannot mistake it for the real one.

For a JWT the header stays, so the server still picks the real key. The payload keeps all claims and gets the claim "apitest": "invalid-token", and every byte of the decoded signature is inverted. Other tokens get every second character replaced by a different character of the same kind.

func Truncate

func Truncate(tok string) string

Truncate returns the first TruncateLen characters of tok, or the first half if tok is not longer. A JWT loses its signature and the end of its payload, so neither a verifier nor code that only decodes the token can accept it. It never returns tok itself.

Types

This section is empty.

Jump to

Keyboard shortcuts

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