Documentation
¶
Overview ¶
Package token generates, parses and hashes opaque bearer tokens.
A token looks like "tss_" followed by 49 base62 characters:
<brand><kind>_<43 random chars><6 checksum chars>
The 43 random characters carry about 256 bits of entropy from crypto/rand. The checksum is CRC32-IEEE over everything before it, encoded as 6 base62 characters. It lets Parse reject typos and garbage before any database lookup, and lets secret scanners match leaked tokens with almost no false positives. It is not a security control.
Only the SHA-256 digest of a token is ever stored.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrMalformed = errors.New("token: malformed") ErrBrand = errors.New("token: invalid brand") )
Errors returned by this package.
Functions ¶
func Generate ¶
Generate returns a new token of the given kind, reading randomness from r. The brand must already be valid (see ValidateBrand).
func Hash ¶
Hash returns the SHA-256 digest of the full token string. This digest is the only form of a token that may be stored.
func ValidateBrand ¶
ValidateBrand reports whether brand is 2 to 6 lowercase ASCII letters.
Types ¶
type Kind ¶
type Kind byte
Kind identifies what a token authenticates. It is the single character between the brand and the underscore.
const ( KindHumanSession Kind = 's' KindAgentSession Kind = 'a' // KindClaimCode ('k', for claim key) is a single-use code that lets a // human claim an agent that signed itself up. It authenticates no // session. KindClaimCode Kind = 'k' KindPAT Kind = 'p' // personal access token KindOAuthAccess Kind = 'o' // OAuth access token KindOAuthRefresh Kind = 'r' // OAuth refresh token KindOAuthCode Kind = 'c' // OAuth authorization code KindDeviceCode Kind = 'd' // OAuth device code // KindPendingSignIn ('i', for in progress) is a sign-in waiting for // another factor. It authenticates no session. KindPendingSignIn Kind = 'i' // KindEmailCode ('e') is a single-use code sent by email, to confirm // an address or reset a password. It authenticates no session. KindEmailCode Kind = 'e' // KindKnownDevice ('n', for known) marks a browser that signed in to // an account with its password, so its attempts get their own limit. // It authenticates no session. KindKnownDevice Kind = 'n' // KindAppKey ('x') is a tensile-auth server's app key: it lets an // app's backend call the server's /v1 API. It authenticates no // session. 'k' was taken by claim codes. KindAppKey Kind = 'x' )
Token kinds. The library fixes the kind; only the brand is configurable.