Documentation
¶
Index ¶
- Variables
- type Claims
- type Config
- type CreateAPIKeyInput
- type CreateAPIKeyResult
- type CreateUserInput
- type CreateWebhookResult
- type Option
- type Service
- func (s *Service) Authenticate(ctx context.Context, username, password string) (*auth.User, error)
- func (s *Service) AuthorizeWebhookRequest(ctx context.Context, dagName, token, signature string, body []byte) (*auth.Webhook, error)
- func (s *Service) ChangePassword(ctx context.Context, userID, oldPassword, newPassword string) error
- func (s *Service) ConfigureWebhookHMAC(ctx context.Context, dagName string, authMode auth.WebhookAuthMode, ...) (*auth.Webhook, error)
- func (s *Service) CountUsers(ctx context.Context) (int64, error)
- func (s *Service) CreateAPIKey(ctx context.Context, input CreateAPIKeyInput, creatorID string) (*CreateAPIKeyResult, error)
- func (s *Service) CreateUser(ctx context.Context, input CreateUserInput) (*auth.User, error)
- func (s *Service) CreateWebhook(ctx context.Context, dagName, creatorID string) (*CreateWebhookResult, error)
- func (s *Service) DeleteAPIKey(ctx context.Context, id string) error
- func (s *Service) DeleteUser(ctx context.Context, id string, currentUserID string) error
- func (s *Service) DeleteWebhook(ctx context.Context, dagName string) error
- func (s *Service) DisableWebhookHMAC(ctx context.Context, dagName string) (*auth.Webhook, error)
- func (s *Service) EnableWebhookHMAC(ctx context.Context, dagName string, authMode auth.WebhookAuthMode, ...) (*WebhookHMACSecretResult, error)
- func (s *Service) GenerateToken(user *auth.User) (*TokenResult, error)
- func (s *Service) GetAPIKey(ctx context.Context, id string) (*auth.APIKey, error)
- func (s *Service) GetUser(ctx context.Context, id string) (*auth.User, error)
- func (s *Service) GetUserFromToken(ctx context.Context, tokenString string) (*auth.User, error)
- func (s *Service) GetWebhookByDAGName(ctx context.Context, dagName string) (*auth.Webhook, error)
- func (s *Service) HasAPIKeyStore() bool
- func (s *Service) HasWebhookStore() bool
- func (s *Service) ListAPIKeys(ctx context.Context) ([]*auth.APIKey, error)
- func (s *Service) ListUsers(ctx context.Context) ([]*auth.User, error)
- func (s *Service) ListWebhooks(ctx context.Context) ([]*auth.Webhook, error)
- func (s *Service) RegenerateWebhookHMACSecret(ctx context.Context, dagName string) (*WebhookHMACSecretResult, error)
- func (s *Service) RegenerateWebhookToken(ctx context.Context, dagName string) (*CreateWebhookResult, error)
- func (s *Service) ResetPassword(ctx context.Context, userID, newPassword string) error
- func (s *Service) ToggleWebhook(ctx context.Context, dagName string, enabled bool) (*auth.Webhook, error)
- func (s *Service) UpdateAPIKey(ctx context.Context, id string, input UpdateAPIKeyInput) (*auth.APIKey, error)
- func (s *Service) UpdateUser(ctx context.Context, id string, input UpdateUserInput) (*auth.User, error)
- func (s *Service) ValidateAPIKey(ctx context.Context, keySecret string) (*auth.APIKey, error)
- func (s *Service) ValidateToken(tokenString string) (*Claims, error)
- func (s *Service) ValidateWebhookToken(ctx context.Context, dagName, token string) (*auth.Webhook, error)
- type TokenResult
- type UpdateAPIKeyInput
- type UpdateUserInput
- type WebhookHMACSecretResult
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidCredentials = errors.New("invalid username or password") ErrInvalidToken = errors.New("invalid or expired token") ErrTokenExpired = errors.New("token has expired") ErrMissingSecret = errors.New("token secret is not configured") ErrPasswordMismatch = errors.New("current password is incorrect") ErrWeakPassword = errors.New("password does not meet requirements") ErrExternalAuthPasswordManagement = errors.New("passwords for externally authenticated users are managed by their authentication provider") ErrCannotDeleteSelf = errors.New("cannot delete your own account") ErrInvalidAPIKey = errors.New("invalid API key") ErrAPIKeyNotConfigured = errors.New("API key management is not configured") ErrInvalidCreatorID = errors.New("creator ID is required") ErrInvalidWebhookToken = errors.New("invalid webhook token") ErrWebhookNotConfigured = errors.New("webhook management is not configured") ErrWebhookDisabled = errors.New("webhook is disabled") ErrInvalidWebhookAuthMode = errors.New("invalid webhook auth mode") ErrInvalidWebhookHMACEnforcementMode = errors.New("invalid webhook HMAC enforcement mode") ErrWebhookHMACNotSupported = errors.New("webhook HMAC is not supported by this store") ErrMissingWebhookHMACSignature = errors.New("missing webhook HMAC signature") ErrInvalidWebhookHMACSignature = errors.New("invalid webhook HMAC signature") ErrWebhookHMACNotConfigured = errors.New("webhook HMAC is not configured") ErrUserDisabled = auth.ErrUserDisabled )
Service errors.
Functions ¶
This section is empty.
Types ¶
type Claims ¶
type Claims struct {
jwt.RegisteredClaims
UserID string `json:"uid"`
Username string `json:"username"`
Role auth.Role `json:"role"`
// PasswordChangedAt is the Unix nanosecond timestamp of the user's last password
// change at token issuance. Zero means the user had never changed their password.
// Tokens issued before a subsequent password change are rejected.
PasswordChangedAt int64 `json:"pwd_changed_at_ns,omitempty"`
}
Claims represents the JWT claims.
type Config ¶
type Config struct {
// TokenSecret is the opaque JWT signing key.
TokenSecret auth.TokenSecret
// TokenTTL is the token time-to-live.
TokenTTL time.Duration
// BcryptCost is the cost factor for bcrypt hashing.
BcryptCost int
}
Config holds the configuration for the auth service.
type CreateAPIKeyInput ¶
type CreateAPIKeyInput struct {
Name string
Description string
Role auth.Role
WorkspaceAccess *auth.WorkspaceAccess
AllowedSurfaces []auth.APIKeySurface
AttributionClass auth.APIKeyAttributionClass
OwnerUserID string
ServiceAccountName string
}
CreateAPIKeyInput contains the input for creating an API key.
type CreateAPIKeyResult ¶
type CreateAPIKeyResult struct {
APIKey *auth.APIKey
FullKey string // Only returned once at creation
}
CreateAPIKeyResult contains the result of creating an API key.
type CreateUserInput ¶
type CreateUserInput struct {
Username string
Password string
Role auth.Role
WorkspaceAccess *auth.WorkspaceAccess
}
CreateUserInput contains the input for creating a user.
type CreateWebhookResult ¶
type CreateWebhookResult struct {
Webhook *auth.Webhook
FullToken string // Only returned once at creation
}
CreateWebhookResult contains the result of creating a webhook.
type Option ¶
type Option func(*Service)
Option is a functional option for configuring the Service.
func WithAPIKeyStore ¶
func WithAPIKeyStore(store auth.APIKeyStore) Option
WithAPIKeyStore sets the API key store for the service.
func WithWebhookStore ¶
func WithWebhookStore(store auth.WebhookStore) Option
WithWebhookStore sets the webhook store for the service.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides authentication and user management functionality.
func New ¶
New creates a new auth service using the provided user store and configuration. If TokenTTL or BcryptCost are not set (<= 0) they are replaced with package defaults.
func (*Service) Authenticate ¶
Authenticate verifies credentials and returns the user if valid.
func (*Service) AuthorizeWebhookRequest ¶
func (s *Service) AuthorizeWebhookRequest( ctx context.Context, dagName, token, signature string, body []byte, ) (*auth.Webhook, error)
AuthorizeWebhookRequest validates the request according to the webhook's auth mode.
func (*Service) ChangePassword ¶
func (s *Service) ChangePassword(ctx context.Context, userID, oldPassword, newPassword string) error
ChangePassword changes a user's password after verifying the old password.
func (*Service) ConfigureWebhookHMAC ¶
func (s *Service) ConfigureWebhookHMAC( ctx context.Context, dagName string, authMode auth.WebhookAuthMode, enforcementMode auth.WebhookHMACEnforcementMode, ) (*auth.Webhook, error)
ConfigureWebhookHMAC updates HMAC auth mode or enforcement without rotating the secret.
func (*Service) CountUsers ¶
CountUsers returns the total number of users in the store.
func (*Service) CreateAPIKey ¶
func (s *Service) CreateAPIKey(ctx context.Context, input CreateAPIKeyInput, creatorID string) (*CreateAPIKeyResult, error)
CreateAPIKey creates a new API key.
func (*Service) CreateUser ¶
CreateUser creates a new user.
func (*Service) CreateWebhook ¶
func (s *Service) CreateWebhook(ctx context.Context, dagName, creatorID string) (*CreateWebhookResult, error)
CreateWebhook creates a new webhook for a DAG.
func (*Service) DeleteAPIKey ¶
DeleteAPIKey deletes an API key by ID.
func (*Service) DeleteUser ¶
DeleteUser deletes a user by ID. The currentUserID prevents users from deleting themselves.
func (*Service) DeleteWebhook ¶
DeleteWebhook deletes a webhook by DAG name.
func (*Service) DisableWebhookHMAC ¶
DisableWebhookHMAC removes HMAC auth from the webhook and returns it to token-only mode.
func (*Service) EnableWebhookHMAC ¶
func (s *Service) EnableWebhookHMAC( ctx context.Context, dagName string, authMode auth.WebhookAuthMode, enforcementMode auth.WebhookHMACEnforcementMode, ) (*WebhookHMACSecretResult, error)
EnableWebhookHMAC configures HMAC auth for an existing webhook and returns the generated secret exactly once.
func (*Service) GenerateToken ¶
func (s *Service) GenerateToken(user *auth.User) (*TokenResult, error)
GenerateToken creates a JWT token for the given user. Returns the token string and its expiry time.
func (*Service) GetUserFromToken ¶
GetUserFromToken validates a token and returns the associated user.
func (*Service) GetWebhookByDAGName ¶
GetWebhookByDAGName retrieves the webhook for a specific DAG.
func (*Service) HasAPIKeyStore ¶
HasAPIKeyStore returns true if API key management is configured.
func (*Service) HasWebhookStore ¶
HasWebhookStore returns true if webhook management is configured.
func (*Service) ListAPIKeys ¶
ListAPIKeys returns all API keys.
func (*Service) ListWebhooks ¶
ListWebhooks returns all webhooks.
func (*Service) RegenerateWebhookHMACSecret ¶
func (s *Service) RegenerateWebhookHMACSecret(ctx context.Context, dagName string) (*WebhookHMACSecretResult, error)
RegenerateWebhookHMACSecret rotates the HMAC secret immediately and returns the new secret exactly once.
func (*Service) RegenerateWebhookToken ¶
func (s *Service) RegenerateWebhookToken(ctx context.Context, dagName string) (*CreateWebhookResult, error)
RegenerateWebhookToken generates a new token for an existing webhook. The old token becomes invalid immediately.
func (*Service) ResetPassword ¶
ResetPassword allows an admin to reset a user's password without knowing the old password.
func (*Service) ToggleWebhook ¶
func (s *Service) ToggleWebhook(ctx context.Context, dagName string, enabled bool) (*auth.Webhook, error)
ToggleWebhook enables or disables a webhook without changing the token.
func (*Service) UpdateAPIKey ¶
func (s *Service) UpdateAPIKey(ctx context.Context, id string, input UpdateAPIKeyInput) (*auth.APIKey, error)
UpdateAPIKey updates an existing API key.
func (*Service) UpdateUser ¶
func (s *Service) UpdateUser(ctx context.Context, id string, input UpdateUserInput) (*auth.User, error)
UpdateUser updates an existing user.
func (*Service) ValidateAPIKey ¶
ValidateAPIKey validates an API key and returns the associated APIKey if valid.
func (*Service) ValidateToken ¶
ValidateToken validates a JWT token and returns the claims.
type TokenResult ¶
TokenResult contains the generated token and its expiry time.
type UpdateAPIKeyInput ¶
type UpdateAPIKeyInput struct {
Name *string
Description *string
Role *auth.Role
WorkspaceAccess *auth.WorkspaceAccess
AllowedSurfaces *[]auth.APIKeySurface
AttributionClass *auth.APIKeyAttributionClass
OwnerUserID *string
ServiceAccountName *string
}
UpdateAPIKeyInput contains the input for updating an API key.
type UpdateUserInput ¶
type UpdateUserInput struct {
Username *string
Role *auth.Role
WorkspaceAccess *auth.WorkspaceAccess
Password *string
IsDisabled *bool
}
UpdateUserInput contains the input for updating a user. Note: Password field is supported by the service for direct usage, but the API handler intentionally omits it - password changes should go through ChangePassword (user self-service) or ResetPassword (admin).
type WebhookHMACSecretResult ¶
type WebhookHMACSecretResult struct {
Webhook *auth.Webhook
FullSecret string // Only returned once at creation or rotation
}
WebhookHMACSecretResult contains the result of enabling or rotating HMAC.