apitokens

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Prefix = "ama_"

Prefix starts every token, so a leaked one is recognisable as authama's.

View Source
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

View Source
var ErrNotFound = errors.New("no API token by that name")

ErrNotFound is a name no token has.

Functions

func File

func File(p paths.Paths) string

File is where the records are kept.

func Revoke

func Revoke(p paths.Paths, name string) error

Revoke removes the token named name.

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

func Check(p paths.Paths, secret, scope string, now time.Time) (Token, bool)

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

func Create(p paths.Paths, name string, days int, now time.Time) (string, Token, error)

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.

func List

func List(p paths.Paths) ([]Token, error)

List is every record, in the order they were made.

func (Token) Allows

func (t Token) Allows(scope string) bool

Allows reports whether t carries scope.

func (Token) Expired

func (t Token) Expired(now time.Time) bool

Expired reports whether t has expired at now.

Jump to

Keyboard shortcuts

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