Documentation
¶
Index ¶
- func FromContext(ctx context.Context) (*output.ValidateOutputBody, bool)
- func GetToken() (*output.CreateTokenOutputBody, error)
- func Init(opts ...Option) error
- func Middleware(next http.Handler) http.Handler
- func VerifyToken(token string) (*output.ValidateOutputBody, error)
- type ClientCredentialsDecorator
- type Config
- type Credentials
- type Decorator
- type ErrMissingRequiredConfig
- type Loader
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶
func FromContext(ctx context.Context) (*output.ValidateOutputBody, bool)
FromContext returns the token information from the request context.
func GetToken ¶
func GetToken() (*output.CreateTokenOutputBody, error)
GetToken requests a new access token from the api-auth server using the provided credentials.
func Init ¶
Init initializes the global configuration for the auth package with the provided options.
func Middleware ¶
Middleware is a middleware that authenticates incoming requests using a Bearer token. It validates the token against the api-auth server using VerifyToken.
func VerifyToken ¶
func VerifyToken(token string) (*output.ValidateOutputBody, error)
VerifyToken validates an access token with the api-auth server.
Types ¶
type ClientCredentialsDecorator ¶
type ClientCredentialsDecorator struct {
// contains filtered or unexported fields
}
ClientCredentialsDecorator implements the Decorator interface using the OAuth 2.0 Client Credentials flow.
func NewClientCredentialsDecorator ¶
func NewClientCredentialsDecorator(clientID, clientSecret string) *ClientCredentialsDecorator
NewClientCredentialsDecorator creates a new instance of ClientCredentialsDecorator.
type Config ¶
type Config struct {
BaseURL string
Credentials *Credentials
Logger *slog.Logger
CredLoader Loader
}
type Credentials ¶
type Credentials struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
}
func NewCredentials ¶
func NewCredentials(clientID, clientSecret string) *Credentials
type Decorator ¶
type Decorator interface {
// Decorate adds authorization to the provided HTTP request.
Decorate(r *http.Request) error
}
Decorator is an interface that defines the Decorate method for adding authorization to an HTTP request.
type ErrMissingRequiredConfig ¶
type ErrMissingRequiredConfig struct {
Field string
}
ErrMissingRequiredConfig is returned when a required configuration field is missing during initialization.
func (*ErrMissingRequiredConfig) Error ¶
func (err *ErrMissingRequiredConfig) Error() string
type Loader ¶
type Loader interface {
Load() (*Credentials, error)
}
type Option ¶
type Option func(*Config)
Option defines a functional option for configuring the auth package.
func WithBaseURL ¶
WithBaseURL sets the base URL for the api-auth server.
func WithLoader ¶
WithLoader sets the loader to be used for loading credentials.
func WithLogger ¶
WithLogger sets the logger to be used by the package.