security

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 11 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.

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

View Source
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

func Session

func Session(ctx context.Context) *schema.Session

Session returns the session of a request the scheme has authenticated, from its context, or nil

func Token

func Token(r *http.Request) string

Token returns a request's session token: its bearer token, or else its session cookie, or empty

Types

type Opt

type Opt func(*Scheme) error

Opt is an option of the scheme

func WithResourceMetadata

func WithResourceMetadata(metadata string) Opt

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.

Jump to

Keyboard shortcuts

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