Documentation
¶
Index ¶
- Constants
- Variables
- func FormatUserCode(code string) string
- type ClientResponse
- type ClientService
- func (s *ClientService) CreateClient(req CreateClientRequest) (*ClientResponse, error)
- func (s *ClientService) DeleteClient(clientID string) error
- func (s *ClientService) GetClient(clientID string) (*models.OAuthClient, error)
- func (s *ClientService) ListClients() ([]models.OAuthClient, error)
- func (s *ClientService) RegenerateSecret(clientID string) (string, error)
- func (s *ClientService) UpdateClient(clientID string, req UpdateClientRequest) error
- func (s *ClientService) VerifyClientSecret(clientID, clientSecret string) error
- type CreateClientRequest
- type DeviceService
- func (s *DeviceService) AuthorizeDeviceCode(userCode, userID string) error
- func (s *DeviceService) GenerateDeviceCode(clientID, scope string) (*models.DeviceCode, error)
- func (s *DeviceService) GetClientNameByUserCode(userCode string) (string, error)
- func (s *DeviceService) GetDeviceCode(deviceCode string) (*models.DeviceCode, error)
- func (s *DeviceService) GetDeviceCodeByUserCode(userCode string) (*models.DeviceCode, error)
- type JWTClaims
- type TokenService
- func (s *TokenService) DisableToken(tokenID string) error
- func (s *TokenService) EnableToken(tokenID string) error
- func (s *TokenService) ExchangeDeviceCode(ctx context.Context, deviceCode, clientID string) (*models.AccessToken, *models.AccessToken, error)
- func (s *TokenService) GetActiveRefreshTokens(userID string) ([]models.AccessToken, error)
- func (s *TokenService) GetUserTokens(userID string) ([]models.AccessToken, error)
- func (s *TokenService) GetUserTokensWithClient(userID string) ([]TokenWithClient, error)
- func (s *TokenService) RefreshAccessToken(ctx context.Context, refreshTokenString, clientID, requestedScopes string) (*models.AccessToken, *models.AccessToken, error)
- func (s *TokenService) RevokeAllUserTokens(userID string) error
- func (s *TokenService) RevokeToken(tokenString string) error
- func (s *TokenService) RevokeTokenByID(tokenID string) error
- func (s *TokenService) RevokeTokenByStatus(tokenID string) error
- func (s *TokenService) ValidateToken(ctx context.Context, tokenString string) (*token.TokenValidationResult, error)
- type TokenWithClient
- type UpdateClientRequest
- type UserService
- func (s *UserService) Authenticate(ctx context.Context, username, password string) (*models.User, error)
- func (s *UserService) AuthenticateWithOAuth(ctx context.Context, provider string, oauthUserInfo *auth.OAuthUserInfo, ...) (*models.User, error)
- func (s *UserService) GetUserByID(id string) (*models.User, error)
Constants ¶
const ( AuthModeLocal = "local" AuthModeHTTPAPI = "http_api" )
Variables ¶
var ( ErrClientNotFound = errors.New("client not found") ErrInvalidClientData = errors.New("invalid client data") ErrClientNameRequired = errors.New("client name is required") )
var ( ErrInvalidClient = errors.New("invalid client_id") ErrClientInactive = errors.New("client is inactive") ErrDeviceCodeNotFound = errors.New("device code not found") ErrDeviceCodeExpired = errors.New("device code expired") ErrUserCodeNotFound = errors.New("user code not found") )
var ( ErrAuthorizationPending = errors.New("authorization_pending") ErrSlowDown = errors.New("slow_down") ErrAccessDenied = errors.New("access_denied") ErrExpiredToken = errors.New("expired_token") )
var ( ErrInvalidCredentials = errors.New("invalid username or password") ErrUserNotFound = errors.New("user not found") ErrAuthProviderFailed = errors.New("authentication provider failed") ErrUserSyncFailed = errors.New("failed to sync user from external provider") ErrUsernameConflict = errors.New("username already exists") ErrOAuthAutoRegisterDisabled = errors.New("OAuth auto-registration is disabled") )
Functions ¶
func FormatUserCode ¶
FormatUserCode formats a user code for display (e.g., "ABCDEFGH" -> "ABCD-EFGH")
Types ¶
type ClientResponse ¶ added in v0.2.0
type ClientResponse struct {
*models.OAuthClient
ClientSecretPlain string // Only populated on creation
}
type ClientService ¶ added in v0.2.0
type ClientService struct {
// contains filtered or unexported fields
}
func NewClientService ¶ added in v0.2.0
func NewClientService(s *store.Store) *ClientService
func (*ClientService) CreateClient ¶ added in v0.2.0
func (s *ClientService) CreateClient(req CreateClientRequest) (*ClientResponse, error)
func (*ClientService) DeleteClient ¶ added in v0.2.0
func (s *ClientService) DeleteClient(clientID string) error
func (*ClientService) GetClient ¶ added in v0.2.0
func (s *ClientService) GetClient(clientID string) (*models.OAuthClient, error)
func (*ClientService) ListClients ¶ added in v0.2.0
func (s *ClientService) ListClients() ([]models.OAuthClient, error)
func (*ClientService) RegenerateSecret ¶ added in v0.2.0
func (s *ClientService) RegenerateSecret(clientID string) (string, error)
func (*ClientService) UpdateClient ¶ added in v0.2.0
func (s *ClientService) UpdateClient(clientID string, req UpdateClientRequest) error
func (*ClientService) VerifyClientSecret ¶ added in v0.2.0
func (s *ClientService) VerifyClientSecret(clientID, clientSecret string) error
type CreateClientRequest ¶ added in v0.2.0
type DeviceService ¶
type DeviceService struct {
// contains filtered or unexported fields
}
func NewDeviceService ¶
func NewDeviceService(s *store.Store, cfg *config.Config) *DeviceService
func (*DeviceService) AuthorizeDeviceCode ¶
func (s *DeviceService) AuthorizeDeviceCode(userCode, userID string) error
AuthorizeDeviceCode marks a device code as authorized by a user
func (*DeviceService) GenerateDeviceCode ¶
func (s *DeviceService) GenerateDeviceCode(clientID, scope string) (*models.DeviceCode, error)
GenerateDeviceCode creates a new device code request
func (*DeviceService) GetClientNameByUserCode ¶
func (s *DeviceService) GetClientNameByUserCode(userCode string) (string, error)
GetClientNameByUserCode retrieves the client name associated with a user code
func (*DeviceService) GetDeviceCode ¶
func (s *DeviceService) GetDeviceCode(deviceCode string) (*models.DeviceCode, error)
GetDeviceCode retrieves a device code by its code
func (*DeviceService) GetDeviceCodeByUserCode ¶
func (s *DeviceService) GetDeviceCodeByUserCode(userCode string) (*models.DeviceCode, error)
GetDeviceCodeByUserCode retrieves a device code by user code
type JWTClaims ¶
type JWTClaims struct {
UserID string `json:"user_id"`
ClientID string `json:"client_id"`
Scopes string `json:"scope"`
jwt.RegisteredClaims
}
type TokenService ¶
type TokenService struct {
// contains filtered or unexported fields
}
func NewTokenService ¶
func NewTokenService( s *store.Store, cfg *config.Config, localProvider *token.LocalTokenProvider, httpProvider *token.HTTPTokenProvider, providerMode string, ) *TokenService
func (*TokenService) DisableToken ¶ added in v0.3.0
func (s *TokenService) DisableToken(tokenID string) error
DisableToken disables a token (can be re-enabled)
func (*TokenService) EnableToken ¶ added in v0.3.0
func (s *TokenService) EnableToken(tokenID string) error
EnableToken re-enables a disabled token
func (*TokenService) ExchangeDeviceCode ¶
func (s *TokenService) ExchangeDeviceCode( ctx context.Context, deviceCode, clientID string, ) (*models.AccessToken, *models.AccessToken, error)
ExchangeDeviceCode exchanges an authorized device code for access and refresh tokens
func (*TokenService) GetActiveRefreshTokens ¶ added in v0.3.0
func (s *TokenService) GetActiveRefreshTokens(userID string) ([]models.AccessToken, error)
GetActiveRefreshTokens gets all active refresh tokens for a user
func (*TokenService) GetUserTokens ¶ added in v0.2.0
func (s *TokenService) GetUserTokens(userID string) ([]models.AccessToken, error)
GetUserTokens returns all active tokens for a user
func (*TokenService) GetUserTokensWithClient ¶ added in v0.2.0
func (s *TokenService) GetUserTokensWithClient(userID string) ([]TokenWithClient, error)
GetUserTokensWithClient returns all active tokens for a user with client information
func (*TokenService) RefreshAccessToken ¶ added in v0.3.0
func (s *TokenService) RefreshAccessToken( ctx context.Context, refreshTokenString, clientID, requestedScopes string, ) (*models.AccessToken, *models.AccessToken, error)
RefreshAccessToken generates new access token (and optionally new refresh token in rotation mode)
func (*TokenService) RevokeAllUserTokens ¶ added in v0.2.0
func (s *TokenService) RevokeAllUserTokens(userID string) error
RevokeAllUserTokens revokes all tokens for a user
func (*TokenService) RevokeToken ¶ added in v0.2.0
func (s *TokenService) RevokeToken(tokenString string) error
RevokeToken revokes a token by its JWT string
func (*TokenService) RevokeTokenByID ¶ added in v0.2.0
func (s *TokenService) RevokeTokenByID(tokenID string) error
RevokeTokenByID revokes a token by its ID
func (*TokenService) RevokeTokenByStatus ¶ added in v0.3.0
func (s *TokenService) RevokeTokenByStatus(tokenID string) error
RevokeTokenByStatus permanently revokes a token (uses status update, not deletion)
func (*TokenService) ValidateToken ¶
func (s *TokenService) ValidateToken( ctx context.Context, tokenString string, ) (*token.TokenValidationResult, error)
ValidateToken validates a JWT token using the configured provider
type TokenWithClient ¶ added in v0.2.0
type TokenWithClient struct {
models.AccessToken
ClientName string
}
TokenWithClient combines token and client information for display
type UpdateClientRequest ¶ added in v0.2.0
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
func NewUserService ¶
func NewUserService( s *store.Store, localProvider *auth.LocalAuthProvider, httpAPIProvider *auth.HTTPAPIAuthProvider, authMode string, oauthAutoRegister bool, ) *UserService
func (*UserService) Authenticate ¶
func (*UserService) AuthenticateWithOAuth ¶ added in v0.6.0
func (s *UserService) AuthenticateWithOAuth( ctx context.Context, provider string, oauthUserInfo *auth.OAuthUserInfo, token *oauth2.Token, ) (*models.User, error)
AuthenticateWithOAuth authenticates a user via OAuth and creates/updates user account
func (*UserService) GetUserByID ¶
func (s *UserService) GetUserByID(id string) (*models.User, error)