Documentation
¶
Overview ¶
Package apitokens keeps the tokens programs use to call authama's API: `ama_` and 32 random bytes, shown once when made. Only a token's SHA-256 is kept, in an owner-only file in the state home, so the file holds nothing a caller could use.
Index ¶
Constants ¶
const Prefix = "ama_"
Prefix starts every token, so a leaked one is recognisable as authama's.
const ScopeRead = "read"
ScopeRead reads the home: profiles, keys, hosts, tokens' presence, the history and the feed. It is the only scope there is.
Variables ¶
var ErrNotFound = errors.New("no API token by that name")
ErrNotFound is a name no token has.
Functions ¶
Types ¶
type Token ¶
type Token struct {
Name string `json:"name"`
Hash string `json:"hash"` // hex SHA-256 of the token
Scopes []string `json:"scopes"`
Created time.Time `json:"created"`
// Expires is the zero time for a token that does not expire.
Expires time.Time `json:"expires,omitzero"`
LastUsed time.Time `json:"last_used,omitzero"`
}
Token is one token's record; never the token itself.
func Check ¶
Check finds the record for secret: a live token with scope. It compares hashes in constant time, and records when the token was last used (at most once a minute, so a busy caller does not rewrite the file on every call).
func Create ¶
Create makes a token named name with the read scope, valid for days (0: no expiry), and returns it with its record. The token is returned only here: nothing can show it again.