Documentation
¶
Index ¶
- func ValidateUserCodeFormat(format string) error
- type CodeGenerator
- type Config
- type Service
- func (s *Service) AuthorizeDevice(ctx context.Context, userCode string, userID, sessionID xid.ID) error
- func (s *Service) CleanupExpiredCodes(ctx context.Context) (int, error)
- func (s *Service) CleanupOldConsumedCodes(ctx context.Context, olderThan time.Duration) (int, error)
- func (s *Service) ConsumeDeviceCode(ctx context.Context, deviceCode string) error
- func (s *Service) DenyDevice(ctx context.Context, userCode string) error
- func (s *Service) GetConfig() Config
- func (s *Service) GetDeviceCodeByDeviceCode(ctx context.Context, deviceCode string) (*schema.DeviceCode, error)
- func (s *Service) GetDeviceCodeByUserCode(ctx context.Context, userCode string) (*schema.DeviceCode, error)
- func (s *Service) InitiateDeviceAuthorization(ctx context.Context, clientID string, scope string, appID, envID xid.ID, ...) (*schema.DeviceCode, error)
- func (s *Service) PollDeviceCode(ctx context.Context, deviceCode string) (*schema.DeviceCode, bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateUserCodeFormat ¶
ValidateUserCodeFormat validates the user code format string.
Types ¶
type CodeGenerator ¶
type CodeGenerator struct {
// contains filtered or unexported fields
}
CodeGenerator generates device codes and user codes.
func NewCodeGenerator ¶
func NewCodeGenerator(userCodeLength int, userCodeFormat string) *CodeGenerator
NewCodeGenerator creates a new code generator.
func (*CodeGenerator) GenerateDeviceCode ¶
func (g *CodeGenerator) GenerateDeviceCode() (string, error)
GenerateDeviceCode generates a long, secure device code (32+ bytes, URL-safe base64).
func (*CodeGenerator) GenerateUserCode ¶
func (g *CodeGenerator) GenerateUserCode() (string, error)
GenerateUserCode generates a short, human-typable code Uses base20 charset (BCDFGHJKLMNPQRSTVWXZ) to avoid ambiguous characters.
type Config ¶
type Config struct {
Enabled bool `json:"enabled"`
DeviceCodeExpiry time.Duration `json:"deviceCodeExpiry"` // e.g., 10 minutes
UserCodeLength int `json:"userCodeLength"` // e.g., 8 characters
UserCodeFormat string `json:"userCodeFormat"` // e.g., "XXXX-XXXX"
PollingInterval int `json:"pollingInterval"` // e.g., 5 seconds
VerificationURI string `json:"verificationUri"` // e.g., "/device"
AllowedClients []string `json:"allowedClients"` // optional whitelist
MaxPollAttempts int `json:"maxPollAttempts"` // max polls before requiring new request
CleanupInterval time.Duration `json:"cleanupInterval"` // how often to clean up expired codes
}
Config holds device flow configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default device flow configuration.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles device flow business logic.
func NewService ¶
func NewService(repo *repo.DeviceCodeRepository, config Config) *Service
NewService creates a new device flow service.
func (*Service) AuthorizeDevice ¶
func (s *Service) AuthorizeDevice(ctx context.Context, userCode string, userID, sessionID xid.ID) error
AuthorizeDevice marks a device as authorized by a user.
func (*Service) CleanupExpiredCodes ¶
CleanupExpiredCodes removes expired device codes.
func (*Service) CleanupOldConsumedCodes ¶
func (s *Service) CleanupOldConsumedCodes(ctx context.Context, olderThan time.Duration) (int, error)
CleanupOldConsumedCodes removes old consumed device codes.
func (*Service) ConsumeDeviceCode ¶
ConsumeDeviceCode marks a device code as consumed after token exchange.
func (*Service) DenyDevice ¶
DenyDevice marks a device authorization as denied.
func (*Service) GetDeviceCodeByDeviceCode ¶
func (s *Service) GetDeviceCodeByDeviceCode(ctx context.Context, deviceCode string) (*schema.DeviceCode, error)
GetDeviceCodeByDeviceCode retrieves a device code by device code.
func (*Service) GetDeviceCodeByUserCode ¶
func (s *Service) GetDeviceCodeByUserCode(ctx context.Context, userCode string) (*schema.DeviceCode, error)
GetDeviceCodeByUserCode retrieves a device code by user code.
func (*Service) InitiateDeviceAuthorization ¶
func (s *Service) InitiateDeviceAuthorization(ctx context.Context, clientID string, scope string, appID, envID xid.ID, orgID *xid.ID) (*schema.DeviceCode, error)
InitiateDeviceAuthorization generates a new device code and user code.
func (*Service) PollDeviceCode ¶
func (s *Service) PollDeviceCode(ctx context.Context, deviceCode string) (*schema.DeviceCode, bool, error)
PollDeviceCode handles device polling for authorization status Returns: dc (*schema.DeviceCode), shouldSlowDown (bool), error.