Documentation
¶
Overview ¶
Package security is the security scheme which the server's operations need, with their scopes: a session's token, as a bearer token, or the session's cookie, which a sign-in sets.
Index ¶
Constants ¶
const ( // Name is the name the scheme is registered with, which operations // need it by Name = "bearerAuth" // CookieName is the name of the cookie with a session's token, which // a sign-in sets, for a browser CookieName = "goauth_session" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Opt ¶
Opt is an option of the scheme
func WithResourceMetadata ¶
WithResourceMetadata says where the API's protected resource metadata is, in a 401's challenge, as RFC 9728 has it, so an OAuth client finds how to be authorized: its URL, or its path, such as /.well-known/oauth-protected-resource/api, which is on the request's host
type Scheme ¶
type Scheme struct {
// contains filtered or unexported fields
}
Scheme authenticates a request with a session, by its token, and needs the scopes an operation has
func New ¶
func New(sessions store.SessionStore, opts ...Opt) (*Scheme, error)
New returns the scheme, with the sessions, which tokens are of
func (*Scheme) Spec ¶
func (s *Scheme) Spec() openapi.SecurityScheme
Spec is the scheme, in the OpenAPI specification: a bearer token, which a browser can send as a cookie instead
func (*Scheme) Wrap ¶
func (s *Scheme) Wrap(handler http.HandlerFunc, scopes []string) http.HandlerFunc
Wrap calls the handler when the request's session, by its bearer token, or else its cookie, has the scopes, with the session in its context. It's 401 without a session, or one which isn't valid, and 403 without the scopes.