jws

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package jws signs and verifies the compact JSON Web Signatures that the Auth-All authorization server issues. It supports ES256 and RS256, and it reads the public JSON Web Key forms of both.

Index

Constants

View Source
const (
	ES256 = "ES256"
	RS256 = "RS256"
)

Algorithms this package supports.

Variables

View Source
var ErrInvalidSignature = errors.New("authall/jws: the signature is invalid")

ErrInvalidSignature reports a token that fails any verification step.

Functions

func Decode

func Decode(s string) ([]byte, error)

Decode reads the base64url form without padding.

func Encode

func Encode(b []byte) string

Encode returns the base64url form without padding.

func PublicJWK

func PublicJWK(pub crypto.PublicKey, algorithm, id string) (map[string]any, error)

PublicJWK returns the public JSON Web Key of a public key.

func PublicKeyFromJWK

func PublicKeyFromJWK(jwk map[string]any) (crypto.PublicKey, error)

PublicKeyFromJWK reads the public key of a JSON Web Key. It accepts the two key types this package signs with.

func Thumbprint

func Thumbprint(jwk map[string]any) (string, error)

Thumbprint returns the RFC 7638 SHA-256 thumbprint of a public JSON Web Key. DPoP uses it as the confirmation value of a bound token.

func Verify

func Verify(token string, pub crypto.PublicKey) ([]byte, error)

Verify checks the signature of a compact token against a public key and returns the payload.

Types

type Header struct {
	Algorithm string `json:"alg"`
	KeyID     string `json:"kid"`
	Type      string `json:"typ"`
	// JWK carries the proof key of a DPoP proof.
	JWK map[string]any `json:"jwk"`
}

Header holds the fields of a compact header that a verifier reads.

func Parse

func Parse(token string) (Header, []byte, error)

Parse splits a compact token and returns the header and the raw payload. It verifies nothing.

type Key

type Key struct {
	ID        string
	Algorithm string
	Private   crypto.Signer
}

Key is one signing key with its identifier.

func Generate

func Generate(algorithm, id string) (*Key, error)

Generate returns a new key of the algorithm.

func (*Key) PublicJWK

func (k *Key) PublicJWK() (string, error)

PublicJWK returns the public JSON Web Key of the key.

func (*Key) Sign

func (k *Key) Sign(typ string, claims any) (string, error)

Sign returns the compact serialization of the claims with the token type in the header.

Jump to

Keyboard shortcuts

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