Documentation
¶
Index ¶
- Constants
- type DefaultDeviceStrategy
- func (h *DefaultDeviceStrategy) DeviceCodeSignature(ctx context.Context, token string) (string, error)
- func (h *DefaultDeviceStrategy) GenerateDeviceCode(ctx context.Context) (string, string, error)
- func (h *DefaultDeviceStrategy) GenerateUserCode(ctx context.Context) (string, string, error)
- func (h *DefaultDeviceStrategy) ShouldRateLimit(context context.Context, code string) (bool, error)
- func (h *DefaultDeviceStrategy) UserCodeSignature(ctx context.Context, token string) (string, error)
- func (h *DefaultDeviceStrategy) ValidateDeviceCode(ctx context.Context, r fosite.DeviceRequester, code string) error
- func (h *DefaultDeviceStrategy) ValidateUserCode(ctx context.Context, r fosite.DeviceRequester, code string) error
- type DeviceAuthHandler
- type DeviceAuthStorage
- type DeviceAuthStorageProvider
- type DeviceCodeStrategy
- type DeviceCodeStrategyProvider
- type DeviceCodeTokenEndpointHandler
- func (v DeviceCodeTokenEndpointHandler) CanHandleRequest(requester fosite.AccessRequester) bool
- func (c *DeviceCodeTokenEndpointHandler) CanHandleTokenEndpointRequest(ctx context.Context, requester fosite.AccessRequester) bool
- func (c *DeviceCodeTokenEndpointHandler) CanSkipClientAuth(ctx context.Context, requester fosite.AccessRequester) bool
- func (c *DeviceCodeTokenEndpointHandler) HandleTokenEndpointRequest(ctx context.Context, requester fosite.AccessRequester) error
- func (c *DeviceCodeTokenEndpointHandler) PopulateTokenEndpointResponse(ctx context.Context, requester fosite.AccessRequester, ...) error
- type DeviceRateLimitStrategy
- type DeviceRateLimitStrategyProvider
- type UserCodeStrategy
- type UserCodeStrategyProvider
Constants ¶
const MaxAttempts = 3
MaxAttempts for retrying the generation of user codes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultDeviceStrategy ¶
type DefaultDeviceStrategy struct {
Enigma *enigma.HMACStrategy
Config interface {
fosite.DeviceProvider
fosite.DeviceAndUserCodeLifespanProvider
fosite.UserCodeProvider
}
}
DefaultDeviceStrategy implements the default device strategy
func (*DefaultDeviceStrategy) DeviceCodeSignature ¶
func (h *DefaultDeviceStrategy) DeviceCodeSignature(ctx context.Context, token string) (string, error)
DeviceCodeSignature generates a device_code signature
func (*DefaultDeviceStrategy) GenerateDeviceCode ¶
GenerateDeviceCode generates a device_code
func (*DefaultDeviceStrategy) GenerateUserCode ¶
GenerateUserCode generates a user_code
func (*DefaultDeviceStrategy) ShouldRateLimit ¶
ShouldRateLimit is used to decide whether a request should be rate-limited
func (*DefaultDeviceStrategy) UserCodeSignature ¶
func (h *DefaultDeviceStrategy) UserCodeSignature(ctx context.Context, token string) (string, error)
UserCodeSignature generates a user_code signature
func (*DefaultDeviceStrategy) ValidateDeviceCode ¶
func (h *DefaultDeviceStrategy) ValidateDeviceCode(ctx context.Context, r fosite.DeviceRequester, code string) error
ValidateDeviceCode validates a device_code
func (*DefaultDeviceStrategy) ValidateUserCode ¶
func (h *DefaultDeviceStrategy) ValidateUserCode(ctx context.Context, r fosite.DeviceRequester, code string) error
ValidateUserCode validates a user_code This function only checks if the device request session is active as we cannot verify the authenticity of the token. Unlike other tokens, the user_code is of limited length, which means that we cannot include the HMAC signature in the token itself. The only way to check the validity of the user_code is to check if its signature is stored in storage.
type DeviceAuthHandler ¶
type DeviceAuthHandler struct {
Storage interface {
DeviceAuthStorageProvider
oauth2.AccessTokenStorageProvider
oauth2.RefreshTokenStorageProvider
}
Strategy interface {
DeviceRateLimitStrategyProvider
DeviceCodeStrategyProvider
UserCodeStrategyProvider
}
Config interface {
fosite.DeviceProvider
fosite.DeviceAndUserCodeLifespanProvider
}
}
DeviceAuthHandler is a response handler for the Device Authorisation Grant as defined in https://tools.ietf.org/html/rfc8628#section-3.1
func (*DeviceAuthHandler) HandleDeviceEndpointRequest ¶
func (d *DeviceAuthHandler) HandleDeviceEndpointRequest(ctx context.Context, dar fosite.DeviceRequester, resp fosite.DeviceResponder) error
HandleDeviceEndpointRequest implements https://tools.ietf.org/html/rfc8628#section-3.1
type DeviceAuthStorage ¶
type DeviceAuthStorage interface {
// CreateDeviceAuthSession stores the device auth request session.
CreateDeviceAuthSession(ctx context.Context, deviceCodeSignature, userCodeSignature string, request fosite.DeviceRequester) (err error)
// GetDeviceCodeSession hydrates the session based on the given device code and returns the device request.
// If the device code has been invalidated with `InvalidateDeviceCodeSession`, this
// method should return the ErrInvalidatedDeviceCode error.
//
// Make sure to also return the fosite.Requester value when returning the fosite.ErrInvalidatedDeviceCode error!
GetDeviceCodeSession(ctx context.Context, signature string, session fosite.Session) (request fosite.DeviceRequester, err error)
// InvalidateDeviceCodeSession is called when a device code is being used. The state of the device
// code should be set to invalid and consecutive requests to GetDeviceCodeSession should return the
// ErrInvalidatedDeviceCode error.
InvalidateDeviceCodeSession(ctx context.Context, signature string) (err error)
}
DeviceAuthStorage handles the device auth session storage
type DeviceAuthStorageProvider ¶
type DeviceAuthStorageProvider interface {
DeviceAuthStorage() DeviceAuthStorage
}
type DeviceCodeStrategy ¶
type DeviceCodeStrategy interface {
// DeviceCodeSignature calculates the signature of a device_code
DeviceCodeSignature(ctx context.Context, code string) (signature string, err error)
// GenerateDeviceCode generates a new device code and signature
GenerateDeviceCode(ctx context.Context) (code string, signature string, err error)
// ValidateDeviceCode validates the device_code
ValidateDeviceCode(ctx context.Context, r fosite.DeviceRequester, code string) (err error)
}
DeviceCodeStrategy handles the device_code strategy
type DeviceCodeStrategyProvider ¶
type DeviceCodeStrategyProvider interface {
DeviceCodeStrategy() DeviceCodeStrategy
}
type DeviceCodeTokenEndpointHandler ¶
type DeviceCodeTokenEndpointHandler struct {
Storage interface {
fosite.Transactional
DeviceAuthStorageProvider
oauth2.AccessTokenStorageProvider
oauth2.RefreshTokenStorageProvider
oauth2.TokenRevocationStorageProvider
}
Strategy interface {
DeviceRateLimitStrategyProvider
DeviceCodeStrategyProvider
UserCodeStrategyProvider
oauth2.AccessTokenStrategyProvider
oauth2.RefreshTokenStrategyProvider
}
Config interface {
fosite.AccessTokenLifespanProvider
fosite.RefreshTokenLifespanProvider
fosite.RefreshTokenScopesProvider
}
}
DeviceCodeTokenEndpointHandler is a token response handler for - the Authorize code grant using the explicit grant type as defined in https://tools.ietf.org/html/rfc6749#section-4.1 - the Device Authorization Grant as defined in https://www.rfc-editor.org/rfc/rfc8628
func (DeviceCodeTokenEndpointHandler) CanHandleRequest ¶
func (v DeviceCodeTokenEndpointHandler) CanHandleRequest(requester fosite.AccessRequester) bool
func (*DeviceCodeTokenEndpointHandler) CanHandleTokenEndpointRequest ¶
func (c *DeviceCodeTokenEndpointHandler) CanHandleTokenEndpointRequest(ctx context.Context, requester fosite.AccessRequester) bool
func (*DeviceCodeTokenEndpointHandler) CanSkipClientAuth ¶
func (c *DeviceCodeTokenEndpointHandler) CanSkipClientAuth(ctx context.Context, requester fosite.AccessRequester) bool
func (*DeviceCodeTokenEndpointHandler) HandleTokenEndpointRequest ¶
func (c *DeviceCodeTokenEndpointHandler) HandleTokenEndpointRequest(ctx context.Context, requester fosite.AccessRequester) error
func (*DeviceCodeTokenEndpointHandler) PopulateTokenEndpointResponse ¶
func (c *DeviceCodeTokenEndpointHandler) PopulateTokenEndpointResponse(ctx context.Context, requester fosite.AccessRequester, responder fosite.AccessResponder) error
type DeviceRateLimitStrategy ¶
type DeviceRateLimitStrategy interface {
// ShouldRateLimit checks whether the token request should be rate-limited
ShouldRateLimit(ctx context.Context, code string) (bool, error)
}
DeviceRateLimitStrategy handles the rate limiting strategy
type DeviceRateLimitStrategyProvider ¶
type DeviceRateLimitStrategyProvider interface {
DeviceRateLimitStrategy() DeviceRateLimitStrategy
}
type UserCodeStrategy ¶
type UserCodeStrategy interface {
// UserCodeSignature calculates the signature of a user_code
UserCodeSignature(ctx context.Context, code string) (signature string, err error)
// GenerateUserCode generates a new user code and signature
GenerateUserCode(ctx context.Context) (code string, signature string, err error)
// ValidateUserCode validates the user_code
ValidateUserCode(ctx context.Context, r fosite.DeviceRequester, code string) (err error)
}
UserCodeStrategy handles the user_code strategy
type UserCodeStrategyProvider ¶
type UserCodeStrategyProvider interface {
UserCodeStrategy() UserCodeStrategy
}