jwt

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package jwt reads JSON Web Tokens without verifying them. patty has no key to check a signature with and never claims to: what it takes from a token is who issued it, to whom, and until when, so a provider can tell its own tokens from everyone else's and say what a leaked one is. Bare tokens of no known issuer are not findings; a provider decides what to report.

Index

Constants

View Source
const Prefix = "eyJ"

Prefix is how the base64url of a JSON object starts, and so every JWT.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Value  string
	Offset int
	Claims Claims
}

Candidate is a token found in content.

func Find

func Find(content []byte) []Candidate

Find returns every well-formed token in content, word-bounded: a token glued to a longer run of base64 is part of that run, not a token.

type Claims

type Claims struct {
	Issuer   string
	Subject  string
	Audience []string
	// Expires and IssuedAt are zero when the token has no exp or iat.
	Expires  time.Time
	IssuedAt time.Time
	Raw      map[string]any
	Header   map[string]any
}

Claims is the decoded payload of a token, with the registered claims picked out and everything kept in Raw.

func Decode

func Decode(token string) (Claims, bool)

Decode splits a token into header, payload and signature and decodes the first two. The signature is kept out: it is not checked. A string that is not three base64url parts with JSON objects in the first two is not a token.

func (Claims) Expired

func (c Claims) Expired(now time.Time) bool

Expired reports whether the token names an expiry that has passed.

func (Claims) Object

func (c Claims) Object(name string) map[string]any

Object reads a nested object claim from the payload, nil when absent.

func (Claims) String

func (c Claims) String(name string) string

String reads a string claim from the payload, "" when absent or not a string.

Jump to

Keyboard shortcuts

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