token

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package token is the mAPI-ng ingest-key wire format, shared by the client SDK (which derives its collector endpoint from the key) and the server (which authenticates the key). Keeping it in the proto module — the one module both sides already import — means client and server agree on the grammar by construction.

A key is:

mk_live_<base64url(origin)>.<secret>

where origin is the full collector origin (scheme://host[:port]) and secret is the random credential. The origin is client-only routing metadata: the server hashes and stores ONLY the secret (see Decode), so the embedded origin never affects auth and can change without invalidating a key. A key with no origin segment (mk_live_<secret>) and a bare legacy key with no prefix (e.g. the dev "dev-key") both decode to that whole value as the secret, so old keys keep working.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(tok string) (origin, secret string, ok bool)

Decode parses a key into its origin (empty if none) and secret. It accepts three forms: a structured token (mk_live_<b64(origin)>.<secret>), a prefixed keyless-origin token (mk_live_<secret>), and a bare legacy secret (no prefix). ok is false only for an empty token or a structured token whose origin segment is not valid base64url or whose secret is empty.

func Encode

func Encode(origin, secret string) string

Encode builds the key for a secret, embedding origin when non-empty. base64url (no padding) keeps the origin free of '.', so the '.' unambiguously separates the origin segment from the secret.

func NewSecret

func NewSecret() (string, error)

NewSecret returns a fresh random secret as unpadded base64url (no '.'), safe to embed as the second segment of a key.

Types

This section is empty.

Jump to

Keyboard shortcuts

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