providers

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAPIKeyProvider

func NewAPIKeyProvider(name string, opts ...APIKeyOption) auth.AuthProvider

NewAPIKeyProvider creates a new API key auth provider. By default, it looks for the API key in the "X-API-Key" header.

func NewBasicAuthProvider

func NewBasicAuthProvider(name string, opts ...BasicAuthOption) auth.AuthProvider

NewBasicAuthProvider creates a new HTTP Basic Auth provider.

func NewBearerTokenProvider

func NewBearerTokenProvider(name string, opts ...BearerTokenOption) auth.AuthProvider

NewBearerTokenProvider creates a new bearer token auth provider. By default, it expects JWT tokens.

func NewOAuth2Provider

func NewOAuth2Provider(name string, flows *auth.OAuthFlows, opts ...OAuth2Option) auth.AuthProvider

NewOAuth2Provider creates a new OAuth2 auth provider.

func NewOIDCProvider

func NewOIDCProvider(name string, openIdConnectUrl string, opts ...OIDCOption) auth.AuthProvider

NewOIDCProvider creates a new OpenID Connect auth provider.

Types

type APIKeyOption

type APIKeyOption func(*APIKeyProvider)

func WithAPIKeyContainer

func WithAPIKeyContainer(container forge.Container) APIKeyOption

WithAPIKeyContainer sets the DI container (for accessing services)

func WithAPIKeyCookie

func WithAPIKeyCookie(name string) APIKeyOption

WithAPIKeyCookie sets the cookie name to look for the API key

func WithAPIKeyDescription

func WithAPIKeyDescription(desc string) APIKeyOption

WithAPIKeyDescription sets the OpenAPI description

func WithAPIKeyHeader

func WithAPIKeyHeader(name string) APIKeyOption

WithAPIKeyHeader sets the header name to look for the API key

func WithAPIKeyQuery

func WithAPIKeyQuery(param string) APIKeyOption

WithAPIKeyQuery sets the query parameter name to look for the API key

func WithAPIKeyValidator

func WithAPIKeyValidator(validator APIKeyValidator) APIKeyOption

WithAPIKeyValidator sets the validator function

type APIKeyProvider

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

APIKeyProvider implements API key authentication. API keys can be provided in headers, query parameters, or cookies.

func (*APIKeyProvider) Authenticate

func (p *APIKeyProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)

func (*APIKeyProvider) Middleware

func (p *APIKeyProvider) Middleware() forge.Middleware

func (*APIKeyProvider) Name

func (p *APIKeyProvider) Name() string

func (*APIKeyProvider) OpenAPIScheme

func (p *APIKeyProvider) OpenAPIScheme() auth.SecurityScheme

func (*APIKeyProvider) Type

type APIKeyValidator

type APIKeyValidator func(ctx context.Context, apiKey string) (*auth.AuthContext, error)

APIKeyValidator validates an API key and returns the auth context. The validator has access to the DI container via the provider and can retrieve services like databases, caches, etc. for validation.

type BasicAuthOption

type BasicAuthOption func(*BasicAuthProvider)

func WithBasicAuthContainer

func WithBasicAuthContainer(container forge.Container) BasicAuthOption

WithBasicAuthContainer sets the DI container (for accessing services)

func WithBasicAuthDescription

func WithBasicAuthDescription(desc string) BasicAuthOption

WithBasicAuthDescription sets the OpenAPI description

func WithBasicAuthValidator

func WithBasicAuthValidator(validator BasicAuthValidator) BasicAuthOption

WithBasicAuthValidator sets the validator function

type BasicAuthProvider

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

BasicAuthProvider implements HTTP Basic Authentication. It extracts username and password from the Authorization header.

func (*BasicAuthProvider) Authenticate

func (p *BasicAuthProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)

func (*BasicAuthProvider) Middleware

func (p *BasicAuthProvider) Middleware() forge.Middleware

func (*BasicAuthProvider) Name

func (p *BasicAuthProvider) Name() string

func (*BasicAuthProvider) OpenAPIScheme

func (p *BasicAuthProvider) OpenAPIScheme() auth.SecurityScheme

func (*BasicAuthProvider) Type

type BasicAuthValidator

type BasicAuthValidator func(ctx context.Context, username, password string) (*auth.AuthContext, error)

BasicAuthValidator validates username and password and returns the auth context. The validator can access services from the DI container to verify credentials against a database, LDAP, etc.

type BearerTokenOption

type BearerTokenOption func(*BearerTokenProvider)

func WithBearerContainer

func WithBearerContainer(container forge.Container) BearerTokenOption

WithBearerContainer sets the DI container (for accessing services)

func WithBearerDescription

func WithBearerDescription(desc string) BearerTokenOption

WithBearerDescription sets the OpenAPI description

func WithBearerFormat

func WithBearerFormat(format string) BearerTokenOption

WithBearerFormat sets the bearer token format (e.g., "JWT", "token")

func WithBearerValidator

func WithBearerValidator(validator BearerTokenValidator) BearerTokenOption

WithBearerValidator sets the validator function

type BearerTokenProvider

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

BearerTokenProvider implements Bearer token authentication (JWT, OAuth2, etc.). It extracts tokens from the Authorization header using the "Bearer" scheme.

func (*BearerTokenProvider) Authenticate

func (p *BearerTokenProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)

func (*BearerTokenProvider) Middleware

func (p *BearerTokenProvider) Middleware() forge.Middleware

func (*BearerTokenProvider) Name

func (p *BearerTokenProvider) Name() string

func (*BearerTokenProvider) OpenAPIScheme

func (p *BearerTokenProvider) OpenAPIScheme() auth.SecurityScheme

func (*BearerTokenProvider) Type

type BearerTokenValidator

type BearerTokenValidator func(ctx context.Context, token string) (*auth.AuthContext, error)

BearerTokenValidator validates a bearer token and returns the auth context. The validator can access services from the DI container for JWT verification, token introspection, etc.

type OAuth2Option

type OAuth2Option func(*OAuth2Provider)

func WithOAuth2Container

func WithOAuth2Container(container forge.Container) OAuth2Option

WithOAuth2Container sets the DI container (for accessing services)

func WithOAuth2Description

func WithOAuth2Description(desc string) OAuth2Option

WithOAuth2Description sets the OpenAPI description

func WithOAuth2Validator

func WithOAuth2Validator(validator OAuth2TokenValidator) OAuth2Option

WithOAuth2Validator sets the validator function

type OAuth2Provider

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

OAuth2Provider implements OAuth 2.0 authentication. It validates OAuth2 access tokens and extracts scopes and permissions.

func (*OAuth2Provider) Authenticate

func (p *OAuth2Provider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)

func (*OAuth2Provider) Middleware

func (p *OAuth2Provider) Middleware() forge.Middleware

func (*OAuth2Provider) Name

func (p *OAuth2Provider) Name() string

func (*OAuth2Provider) OpenAPIScheme

func (p *OAuth2Provider) OpenAPIScheme() auth.SecurityScheme

func (*OAuth2Provider) Type

type OAuth2TokenValidator

type OAuth2TokenValidator func(ctx context.Context, token string) (*auth.AuthContext, error)

OAuth2TokenValidator validates an OAuth2 token and returns the auth context. The validator should verify the token with the OAuth2 authorization server and extract claims, scopes, etc.

type OIDCOption

type OIDCOption func(*OIDCProvider)

func WithOIDCContainer

func WithOIDCContainer(container forge.Container) OIDCOption

WithOIDCContainer sets the DI container (for accessing services)

func WithOIDCDescription

func WithOIDCDescription(desc string) OIDCOption

WithOIDCDescription sets the OpenAPI description

func WithOIDCValidator

func WithOIDCValidator(validator OIDCTokenValidator) OIDCOption

WithOIDCValidator sets the validator function

type OIDCProvider

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

OIDCProvider implements OpenID Connect authentication. It validates OIDC ID tokens and access tokens.

func (*OIDCProvider) Authenticate

func (p *OIDCProvider) Authenticate(ctx context.Context, r *http.Request) (*auth.AuthContext, error)

func (*OIDCProvider) Middleware

func (p *OIDCProvider) Middleware() forge.Middleware

func (*OIDCProvider) Name

func (p *OIDCProvider) Name() string

func (*OIDCProvider) OpenAPIScheme

func (p *OIDCProvider) OpenAPIScheme() auth.SecurityScheme

func (*OIDCProvider) Type

type OIDCTokenValidator

type OIDCTokenValidator func(ctx context.Context, token string) (*auth.AuthContext, error)

OIDCTokenValidator validates an OIDC token and returns the auth context. The validator should verify the token with the OIDC provider and extract claims (sub, email, name, etc.).

Jump to

Keyboard shortcuts

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