httphandler

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 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.

README

Credential Handlers

Credentials

Credentials store secret material, such as API keys or tokens, under a key, for other parts of the system to authenticate with third-party services. A credential's value is only returned with the passphrase it was encrypted with, so only for backends which encrypt with their own passphrases (file and pg). Other backends, such as AWS and Bitwarden Secrets Manager, never return values over HTTP.

GET /credential

List the stored credentials in key order, without their values. Credentials from the environment aren't listed. Returns count, and each credential's key and description, with the time it was last changed, when the backend records it. Needs the credential:read scope.

PUT /credential

Store a credential, replacing any credential with the same key. The request body is a JSON object with the key, an identifier of up to 64 letters, digits, _ and -, starting with a letter, and the credentials, which can be any JSON value, and, optionally, its description, such as what it's for, which is kept when it isn't set, and removed when it's empty. Returns the key, and the description, when it's set. Returns 400 if the key or credentials are invalid, 403 if the backend refuses the write, or 503 if the backend has no passphrase. Needs the credential:write scope.

GET /credential/{key}

Get the key of a stored credential, its description, and the time it was last changed, without its value. Use it to check that a credential exists. Returns 400 if the key is invalid, or 404 if there's no credential for the key. Needs the credential:read scope.

POST /credential/{key}

Get a credential's value, with the passphrase it was encrypted with as the request body, as text/plain, which must match exactly, including any spaces or line endings. This is a POST rather than a GET, as the request has a body, and the response is sent with Cache-Control: no-store, so the value isn't cached. Returns the credential as JSON. Returns 400 if the key or request body is invalid, 403 if the passphrase isn't the credential's passphrase, or 404 if there's no credential for the key. Only for backends which encrypt with their own passphrases. Needs the credential:decrypt scope.

PATCH /credential/{key}

Change a stored credential's description, without its value. The request body is a JSON object with its description, which is removed when it's empty. Returns the key, and the description. Returns 400 if the key or request body is invalid, 403 if the backend refuses the write, or 404 if there's no credential for the key. Needs the credential:write scope.

DELETE /credential/{key}

Delete a stored credential. A credential from the environment can't be deleted. Returns 400 if the key is invalid, or 404 if there's no credential for the key. Needs the credential:write scope.

POST /credential/{key}/rotate

Re-encrypt a credential with the latest passphrase version, without changing its value, after a new passphrase version is added. Returns 304 if the credential already uses the latest passphrase version, 400 if the key is invalid, 404 if there's no credential for the key, or 503 if no passphrase is configured. Only for backends which encrypt with their own passphrases. Needs the credential:write scope.

POST /credential/{key}/signin

Store a sign-in, as the credential, when the server registers an authorization server for the key's prefix, such as GOOGLE_ for Google. A client, such as a command line tool, gets how to sign in from a server, signs in at the authorization server with PKCE, which redirects to a loopback address with a code, and sends the code here. The server exchanges it with the OAuth client which is the value of the client credential, such as GOOGLE_CLIENT, as its client_id and client_secret, or the file Google's console downloads, so the client's secret stays on the server. The grant, with its tokens, is stored without the secret. The request body is a JSON object with the code, its code_verifier, and the redirect_uri, which must be a loopback address. Returns the key, the server's issuer, and the scopes it granted, without the tokens. Returns 400 if the key, request body or redirect is invalid, the key isn't a sign-in's, or the server refuses the code, 403 if the backend refuses the write, or 503 if there's no client, the server refuses the client, or the server fails. Needs the credential:write scope.

Documentation

Index

Constants

View Source
const (

	// Table is the table of the changes which are published, which a web UI
	// follows
	Table = "credential"
)

Variables

View Source
var HandlerDoc []byte

Functions

func RegisterManagerHandlers

func RegisterManagerHandlers(manager credential.CredentialManager, auth bool, with ...Opt) func(*httprouter.Router) error

RegisterManagerHandlers registers the handlers for a credential manager: the provider's handlers, and listing, getting the metadata of, deleting and, when the manager encrypts with its own passphrases, rotating credentials. Register the provider's or the manager's handlers, not both. When auth is true, the handlers need the credential scopes.

func RegisterProviderHandlers

func RegisterProviderHandlers(provider credential.CredentialProvider, auth bool, with ...Opt) func(*httprouter.Router) error

RegisterProviderHandlers registers the handlers for a credential provider: storing a credential, and, when the provider encrypts with its own passphrases, getting a value with its passphrase. Values are never returned without the passphrase. When auth is true, the handlers need the credential scopes.

Types

type Opt

type Opt func(*options)

Opt is an option of the handlers

func WithPublisher

func WithPublisher(publisher Publisher) Opt

WithPublisher publishes a change of a credential, by its key, without its value, after it's stored, described, rotated or deleted, so a web UI which follows the changes loads the credentials again

func WithSignIn added in v0.0.20

func WithSignIn(prefix string, server authclient.ServerMetadata, client string) Opt

WithSignIn stores the sign-ins with the server, such as Google, as the credentials whose keys have the prefix, such as GOOGLE_, other than the client's: a code, which a client authorized at a loopback address, is exchanged with the client, which is the value of the credential with the client key, as its client_id and client_secret, and the grant is stored, without the secret. It can be given more than once: a key is the sign-in of the server with the longest of its prefixes, and no key of a client is a sign-in.

type Publisher

type Publisher interface {
	Publish(schema.Change) int
}

Publisher publishes changes, such as go-server's broadcaster, which a web UI follows

Jump to

Keyboard shortcuts

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