Documentation
¶
Overview ¶
Package clients provides a record of conceptual clients that will be interacting with Lockbox.
Clients represent an actor in the system, a deployment of software that needs access to certain Lockbox (and third-party) APIs. Clients are largely useful for keeping track of where requests came from and limiting the scopes available in certain situations.
The clients package provides the definitions of the service and its boundaries. It sets up the Client type, which represents an API consumer, the RedirectURI type, which represents a URI that a client's authentication requests are able to be redirected to, and the Storer interface, which defines how to implement data storage backends for these Clients and RedirectURIs.
This package can be thought of as providing the types and helpers that form the conceptual framework of the subsystem, but with very little functionality provided by itself. Instead, implementations of the interfaces and sub-packages using these types are where most functionality will actually live.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClientAlreadyExists is returned when a client with the same ID // already exists in a Storer. ErrClientAlreadyExists = errors.New("client already exists") // ErrClientNotFound is returned when a client can't be located in a // Storer. ErrClientNotFound = errors.New("client not found") // ErrIncorrectSecret is returned when a client tries to authenticate // with an invalid secret. ErrIncorrectSecret = errors.New("incorrect client secret") // ErrUnsupportedSecretScheme is returned when a client uses a secret // scheme that we don't know how to use. ErrUnsupportedSecretScheme = errors.New("an unsupported secret scheme was used") )
Functions ¶
func RedirectURIsByURI ¶
func RedirectURIsByURI(uris []RedirectURI)
RedirectURIsByURI returns `uris` sorted by their URI property, with URIs that are lexicographically lower returned first.
Types ¶
type Change ¶
Change represents a change we'd like to make to a Client. Nil values always represent "no change", whereas empty values will be interpreted as a desire to set the property to the empty value.
func ChangeSecret ¶
ChangeSecret generates a Change that will update a Client's secret.
type Client ¶
type Client struct { ID string // unique ID per client Name string // friendly name for this client SecretHash string // hash of unique secret to authenticate with (optional) SecretScheme string // the hashing scheme used for the secret Confidential bool // whether this is a confidential (true) or public (false) client CreatedAt time.Time // timestamp of creation CreatedBy string // the HMAC key that created this client CreatedByIP string // the IP that created this client }
Client represents an API client.
func (Client) CheckSecret ¶
CheckSecret returns nil if the passed secret is correct for the Client, or ErrIncorrectSecret if the secret is incorrect. Any other error signals data corruption.
type ErrRedirectURIAlreadyExists ¶
type ErrRedirectURIAlreadyExists struct { ID string URI string // the URI that already exists Err error // the error that was returned, if any }
ErrRedirectURIAlreadyExists is returned when a redirect URI already exists in a Storer.
func (ErrRedirectURIAlreadyExists) Error ¶
func (e ErrRedirectURIAlreadyExists) Error() string
Error fills the error interface for RedirectURIs.
type RedirectURI ¶
type RedirectURI struct { ID string // unique ID per redirect URI URI string // the URI to redirect to IsBaseURI bool // whether this is the full URI (false) or just a base (true) ClientID string // the ID of the Client this redirect URI applies to CreatedAt time.Time // the timestamp this redirect URI was created at CreatedBy string // the HMAC key that created this redirect URI CreatedByIP string // the IP that created this redirect URI }
RedirectURI represents a URI that we'll redirect to as part of the OAuth 2 dance for a Client. The RedirectURI is an important part of authorizing a client, especially a public one, as it prevents others from using a Client's ID.
type Storer ¶
type Storer interface { Create(ctx context.Context, client Client) error Get(ctx context.Context, id string) (Client, error) ListRedirectURIs(ctx context.Context, clientID string) ([]RedirectURI, error) Update(ctx context.Context, id string, change Change) error Delete(ctx context.Context, id string) error AddRedirectURIs(ctx context.Context, uris []RedirectURI) error RemoveRedirectURIs(ctx context.Context, ids []string) error }
Storer is an interface for storing, retrieving, and modifying Clients and the metadata surrounding them.
Directories
¶
Path | Synopsis |
---|---|
Package apiv1 provides a JSON API for interacting with clients.
|
Package apiv1 provides a JSON API for interacting with clients. |
storers
|
|
memory
Package memory provides an in-memory implementation of the lockbox.dev/clients.Storer interface.
|
Package memory provides an in-memory implementation of the lockbox.dev/clients.Storer interface. |
postgres
Package postgres provides an implementation of the lockbox.dev/clients.Storer interface that stores data in a PostgreSQL database.
|
Package postgres provides an implementation of the lockbox.dev/clients.Storer interface that stores data in a PostgreSQL database. |
postgres/migrations
Package migrations provides access to the SQL migrations used to set up a PostgreSQL database for the postgres Storer implementation.
|
Package migrations provides access to the SQL migrations used to set up a PostgreSQL database for the postgres Storer implementation. |