Documentation
¶
Overview ¶
Package auth provides authentication and authorization functionality. It includes JWT token handling, OIDC integration, HTTP middleware, and role-based access control.
Index ¶
- func GetUserIDFromContext(ctx context.Context) (string, bool)
- func GetUserRolesFromContext(ctx context.Context) ([]string, bool)
- func IsAuthenticated(ctx context.Context) bool
- func ValidateConfig(config Config) *validation.ValidationResult
- func WithUserID(ctx context.Context, userID string) context.Context
- func WithUserRoles(ctx context.Context, roles []string) context.Context
- type Auth
- func (a *Auth) GenerateToken(ctx context.Context, userID string, roles []string, scopes []string, ...) (string, error)
- func (a *Auth) GetUserID(ctx context.Context) (string, error)
- func (a *Auth) GetUserRoles(ctx context.Context) ([]string, error)
- func (a *Auth) HasRole(ctx context.Context, role string) (bool, error)
- func (a *Auth) IsAdmin(ctx context.Context) (bool, error)
- func (a *Auth) IsAuthorized(ctx context.Context, operation string) (bool, error)
- func (a *Auth) Middleware() func(http.Handler) http.Handler
- func (a *Auth) ValidateToken(ctx context.Context, tokenString string) (*jwt.Claims, error)
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetUserIDFromContext ¶
GetUserIDFromContext retrieves the user ID from the context.
func GetUserRolesFromContext ¶
GetUserRolesFromContext retrieves the user roles from the context.
func IsAuthenticated ¶
IsAuthenticated checks if the user is authenticated.
func ValidateConfig ¶
func ValidateConfig(config Config) *validation.ValidationResult
ValidateConfig validates the configuration for the auth module.
func WithUserID ¶
WithUserID returns a new context with the user ID.
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth provides authentication and authorization functionality.
func (*Auth) GenerateToken ¶
func (a *Auth) GenerateToken(ctx context.Context, userID string, roles []string, scopes []string, resources []string) (string, error)
GenerateToken generates a new JWT token for a user with the specified roles, scopes, and resources.
func (*Auth) GetUserRoles ¶
GetUserRoles retrieves the user roles from the context.
func (*Auth) IsAuthorized ¶
IsAuthorized checks if the user is authorized to perform the operation.
func (*Auth) Middleware ¶
Middleware returns the HTTP middleware for authentication.
type Config ¶
type Config struct {
// JWT configuration
JWT struct {
// SecretKey is the key used to sign and verify JWT tokens
SecretKey string
// TokenDuration is the validity period for generated tokens
TokenDuration time.Duration
// Issuer identifies the entity that issued the token
Issuer string
// Remote validation configuration
Remote struct {
// Enabled determines if remote validation should be used
Enabled bool
// ValidationURL is the URL of the remote validation endpoint
ValidationURL string
// ClientID is the client ID for the remote validation service
ClientID string
// ClientSecret is the client secret for the remote validation service
ClientSecret string
// Timeout is the timeout for remote validation operations
Timeout time.Duration
}
}
// OIDC configuration
OIDC struct {
// IssuerURL is the URL of the OIDC provider
IssuerURL string
// ClientID is the client ID for the OIDC provider
ClientID string
// ClientSecret is the client secret for the OIDC provider
ClientSecret string
// RedirectURL is the redirect URL for the OIDC provider
RedirectURL string
// Scopes are the OAuth2 scopes to request
Scopes []string
// Timeout is the timeout for OIDC operations
Timeout time.Duration
}
// Middleware configuration
Middleware struct {
// SkipPaths are paths that should skip authentication
SkipPaths []string
// RequireAuth determines if authentication is required for all requests
RequireAuth bool
}
// Service configuration
Service struct {
// AdminRoleName is the name of the admin role
AdminRoleName string
// ReadOnlyRoleName is the name of the read-only role
ReadOnlyRoleName string
// ReadOperationPrefixes are prefixes for read-only operations
ReadOperationPrefixes []string
}
}
Config holds the configuration for the auth module.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default configuration for the auth module.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package config provides adapters for auth configuration.
|
Package config provides adapters for auth configuration. |
|
Package errors provides comprehensive error handling for the auth module.
|
Package errors provides comprehensive error handling for the auth module. |
|
Package jwt provides JWT token handling for the auth module.
|
Package jwt provides JWT token handling for the auth module. |
|
Package middleware provides HTTP middleware for authentication.
|
Package middleware provides HTTP middleware for authentication. |
|
Package oidc provides OpenID Connect integration for the auth module.
|
Package oidc provides OpenID Connect integration for the auth module. |
|
Package service provides authorization services for the auth module.
|
Package service provides authorization services for the auth module. |