apikey

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package apikey is a provider for services that issue a static API key or token, driven by configuration: where the token goes in a request, which endpoint verifies it, and where the account is in the response.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotJSON = errors.New("apikey: response is not JSON")

ErrNotJSON is returned when a validation response is not JSON.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Manifest is the provider's manifest. It needs an auth method with key
	// Method whose fields include Field.
	Manifest provider.Manifest
	// Method is the auth method's key. Default "api_token".
	Method string
	// Field is the credential field holding the token. Default "token".
	Field string
	// Header is the request header that carries the token. Default
	// "Authorization".
	Header string
	// Prefix precedes the token in the header. Default "Bearer " when Header
	// is Authorization, otherwise none.
	Prefix string
	// Verify is the request that validates the token. Required.
	Verify Request
	// Account, if set, is a second request that discovers the account, for
	// providers whose verification response does not name it.
	Account *Request
}

Config describes a static-token provider.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is a static-token provider.

func New

func New(cfg Config) (*Provider, error)

New returns a provider for cfg.

func (*Provider) Authenticate

func (p *Provider) Authenticate(r *http.Request, m provider.Material) error

Authenticate implements provider.Provider.

func (*Provider) Manifest

func (p *Provider) Manifest() provider.Manifest

Manifest implements provider.Provider.

func (*Provider) Validate

func (p *Provider) Validate(ctx context.Context, hc *http.Client, m provider.Material) (provider.Result, error)

Validate implements provider.Provider.

type Request

type Request struct {
	Path             string
	AccountIDPath    string
	AccountLabelPath string
	// ScopesPath, if set, names an array of strings.
	ScopesPath string
}

Request is a GET to a path under the manifest's first base URL, and where to find the account in its JSON response. Paths are dot-separated keys and array indexes, for example "result.0.id".

Jump to

Keyboard shortcuts

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