Documentation
¶
Overview ¶
Package apikeys finds who sends a request by a key a program sends with it (the header Authorization: Bearer <key>), for a program that uses the API as a person of the organization: another system that makes requests, or says what became of the work an approval started. The keys are listed in a file, each with the person it stands for and the roles the gate is told of, as the SHA-256 of the key: the file holds no key itself (Parse, ReadFile). An Authenticator finds the person of a request that sends a key, while the organization in effect today has them, and leaves a request with no key to the sign-in of the people (Config.Next). Package serve reads such a file with -api-keys.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
Authenticator finds who sends a request by its key. It is a server.Authenticator.
func New ¶
func New(cfg Config) (*Authenticator, error)
New makes an Authenticator of cfg. It refuses two keys with one sum.
func (*Authenticator) Authenticate ¶
Authenticate answers the person of the key a request sends in its header Authorization ("Bearer <key>", the scheme in any case), with the roles of its line, while Config.Known has them. A key no line has, an empty one, and one of a person Known does not have stand for no one (server.ErrNoPerson: the answer is 401), whatever else the request carries. A request with no key is Config.Next's. An error of Known is answered as it is (500).
type Config ¶
type Config struct {
// Keys are the keys programs send (Parse).
Keys []Key
// Next finds who sends a request with no key: the sign-in of the people (the provider's, say).
// nil answers server.ErrNoPerson for such a request.
Next server.Authenticator
// Known reports whether the organization in effect today has a person (Server.InOrganization):
// a key of a person it does not have stands for no one, so that the key of someone who left
// stops working with the data that says so. nil takes every person of the keys.
Known func(ctx context.Context, person string) (bool, error)
// Logger logs a key refused, as a warning that names the reason and not the key; nil is
// slog.Default().
Logger *slog.Logger
}
Config is how an Authenticator finds who sends a request.
type Key ¶
type Key struct {
// Person is the ID, in the organization's data, of the person the key stands for.
Person string
// Roles are what the gate is told of them (server.Person.Roles): none for no role.
Roles []string
// Sum is the SHA-256 of the key.
Sum [sha256.Size]byte
// Line is the line of the file the key is on, from 1.
Line int
}
Key is a key a program sends, as a line of a file of keys holds it.
func Parse ¶
Parse reads a file of keys: a line for each key, with the ID of the person it stands for, the SHA-256 of the key in 64 hexadecimal digits, and, when the person has roles, the roles separated by commas, the three separated by spaces or tabs:
# the purchasing system, which says what became of the orders b0001 2d711642b726b04401627ca9fbac32f5c8530fb1903cc4db02258717921a4881 s1001 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 system_admin # a script
A word that begins with # begins a comment, to the end of the line, and a blank line is left out. A person may have more than one key (while a program changes to a new one, say). Parse refuses, naming the line: a line of another shape, a sum that is not 64 hexadecimal digits, more than 16 roles, a role of more than 64 bytes or with a character that is not visible ASCII, and the sum of a line before.