Documentation
¶
Index ¶
- Variables
- type APIKey
- type APIKeyEvent
- type Device
- type Flow
- type Github
- type Google
- type Health
- type HealthErrors
- type Magic
- type Registration
- type RegistrationEvent
- type SecretKey
- type SecretKeyEvent
- type ServiceKey
- type ServiceSession
- type ServiceSessionEvent
- type Session
- type SessionEvent
- type Storage
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when a key is not found. ErrNotFound = errors.New("key not found") // ErrAlreadyExists is returned when a key already exists. ErrAlreadyExists = errors.New("key already exists") )
Functions ¶
This section is empty.
Types ¶
type APIKey ¶
type APIKey interface {
// GetAPIKey returns the API key for the given identifier. If
// there is an error while getting the API key, an error is returned.
// If there is no error, the API key is returned. If the API key does not
// exist, ErrNotFound is returned.
GetAPIKey(ctx context.Context, identifier string) (*apikey.APIKey, error)
// ListAPIKeys returns a list of all API Keys. If there is an error while
// listing the API keys, an error is returned. If there is no error, the list
// of API keys is returned. If there are no API keys, an empty list is returned.
ListAPIKeys(ctx context.Context) ([]*apikey.APIKey, error)
// SubscribeToAPIKeys subscribes to API key events. When an API key is created,
// updated, or deleted, the event is emitted on the given channel. Cancelling
// the provided context will unsubscribe from API key events.
//
// The storage implementation is responsible for ensuring that the channel is not
// interrupted by network errors, etc. The channel should only be closed
// when the context is cancelled.
SubscribeToAPIKeys(ctx context.Context) <-chan *APIKeyEvent
}
APIKey is the interface for storage of API Keys.
type APIKeyEvent ¶
type APIKeyEvent struct {
// Identifier is the API Key Identifier
Identifier string
// Deleted indicates whether the API Key was deleted
Deleted bool
// APIKey is the API Key that was created or updated.
// If the API Key was deleted, this will be nil
APIKey *apikey.APIKey
}
APIKeyEvent is the event that is emitted when an API key is created, updated, or deleted
type Device ¶
type Device interface {
SetDeviceFlow(ctx context.Context, identifier string, deviceCode string, userCode string) error
GetDeviceFlow(ctx context.Context, deviceCode string) (*flow.Device, error)
UpdateDeviceFlow(ctx context.Context, identifier string, sessionID string, encryptedSession string, expiry time.Time) error
GetDeviceFlowUserCode(ctx context.Context, userCode string) (*flow.Device, error)
GetDeviceFlowIdentifier(ctx context.Context, identifier string) (*flow.Device, error)
DeleteDeviceFlow(ctx context.Context, deviceCode string) error
GCDeviceFlow(ctx context.Context, expiry time.Duration) (int, error)
}
type Github ¶
type Github interface {
SetGithubFlow(ctx context.Context, state string, verifier string, challenge string, nextURL string, organization string, deviceIdentifier string) error
GetGithubFlow(ctx context.Context, state string) (*flow.Github, error)
DeleteGithubFlow(ctx context.Context, state string) error
GCGithubFlow(ctx context.Context, expiry time.Duration) (int, error)
}
type Google ¶
type Google interface {
SetGoogleFlow(ctx context.Context, state string, verifier string, challenge string, nextURL string, organization string, deviceIdentifier string) error
GetGoogleFlow(ctx context.Context, state string) (*flow.Google, error)
DeleteGoogleFlow(ctx context.Context, state string) error
GCGoogleFlow(ctx context.Context, expiry time.Duration) (int, error)
}
type Health ¶
type Health interface {
// Errors returns the errors that may have occurred while checking the health of the storage implementation.
//
// The returned HealthErrors cannot be nil, and if there are no errors the HealthErrors should contain
// nil values for each error.
Errors() HealthErrors
}
Health is meant to be implemented by the storage to check the status of the storage implementation.
type HealthErrors ¶
type HealthErrors struct {
RegistrationError error
SecretKeyError error
APIKeyError error
ServiceSessionError error
SessionError error
}
HealthErrors contains errors that may have occurred while checking the health of the storage implementation.
type Magic ¶
type Magic interface {
SetMagicFlow(ctx context.Context, email string, salt []byte, hash []byte, ip string, nextURL string, organization string, deviceIdentifier string) error
GetMagicFlow(ctx context.Context, email string) (*flow.Magic, error)
DeleteMagicFlow(ctx context.Context, email string) error
GCMagicFlow(ctx context.Context, expiry time.Duration) (int, error)
}
type Registration ¶
type Registration interface {
// SetRegistration sets whether registration is enabled. If there is an error
// while setting the registration status, an error is returned.
SetRegistration(ctx context.Context, enabled bool) error
// GetRegistration returns whether registration is enabled. If there is an error
// while getting the registration status, an error is returned. If there is no
// error, the boolean indicates whether registration is enabled.
GetRegistration(ctx context.Context) (bool, error)
// SubscribeToRegistration subscribes to registration events. When registration
// is enabled or disabled, the event is emitted on the given channel. Cancelling
// the provided context will unsubscribe from registration events.
//
// The storage implementation is responsible for ensuring that the channel is not
// interrupted by network errors, etc. The channel should only be closed
// when the context is cancelled.
SubscribeToRegistration(ctx context.Context) <-chan *RegistrationEvent
}
Registration is the interface for storage of registration settings.
type RegistrationEvent ¶
type RegistrationEvent struct {
// Enabled indicates whether registration is enabled
Enabled bool
}
RegistrationEvent is the event that is emitted when registration is enabled or disabled
type SecretKey ¶
type SecretKey interface {
// SetSecretKey sets the current secret key. If there is an error while
// setting the secret key, an error is returned.
// If there is no error, the secret key is returned.
SetSecretKey(ctx context.Context, secretKey [32]byte) error
// GetSecretKey returns the current secret key. If there is an error while
// getting the secret key, an error is returned. If the secret key does not
// exist, ErrNotFound is returned. If there is no error, the secret
// key is returned.
GetSecretKey(ctx context.Context) ([32]byte, error)
// SubscribeToSecretKey subscribes to secret key events. When the secret key is
// rotated, the event is emitted on the given channel. Cancelling the provided
// context will unsubscribe from secret key events.
//
// The storage implementation is responsible for ensuring that the channel is not
// interrupted by network errors, etc. The channel should only be closed
// when the context is cancelled.
SubscribeToSecretKey(ctx context.Context) <-chan SecretKeyEvent
}
SecretKey is the interface for managing the secret keys used to sign and verify sessions.
type SecretKeyEvent ¶
type SecretKeyEvent [32]byte
SecretKeyEvent is the event that is emitted when a secret key is rotated, and contains the new secret key.
type ServiceKey ¶
type ServiceKey interface {
// GetServiceKey returns the service key for the given identifier. If there is an error
// while getting the service key, an error is returned. If there is no error, the service key
// is returned. If the service key does not exist, ErrNotFound is returned.
GetServiceKey(ctx context.Context, identifier string) (*servicekey.ServiceKey, error)
// IncrementServiceKeyNumUsed increments the number of times the service key has been used by increment.
// If there is an error while incrementing the number of times the service key has been used,
// an error is returned. If the service key does not exist, ErrNotFound is returned.
IncrementServiceKeyNumUsed(ctx context.Context, identifier string, increment int64) error
}
type ServiceSession ¶
type ServiceSession interface {
// SetServiceSession sets the service session for the given service session identifier. If
// there is an error while setting the service session, an error is returned.
// If the user or organization does not exist, ErrNotFound is returned.
// If the organization associated with the service session is not empty,
// service the session is associated with the organization. If the service session is
// associated with an organization and that organization is deleted, the service session
// should also be deleted. If the service session already exists, it ErrAlreadyExists is returned.
SetServiceSession(ctx context.Context, identifier string, salt []byte, hash []byte, serviceKeyID string) error
// GetServiceSession gets the service session for the given identifier. If there is an error
// while getting the service session, an error is returned. If the service session does not
// exist, ErrNotFound is returned.
GetServiceSession(ctx context.Context, identifier string) (*servicesession.ServiceSession, error)
// ListServiceSessions returns a list of all service sessions. If there is an error while
// listing the service sessions, an error is returned.
// If there is no error, the list of service sessions is returned. If there are no service sessions,
// an empty list is returned.
ListServiceSessions(ctx context.Context) ([]*servicesession.ServiceSession, error)
// DeleteServiceSession deletes the service session for the given identifier. If
// there is an error while deleting the service session, an error is returned.
// ErrNotFound is returned if the service session does not exist.
DeleteServiceSession(ctx context.Context, identifier string) error
// SubscribeToServiceSessions subscribes to service session events. When a service session is created,
// updated, or deleted, the event is emitted on the given channel. Cancelling
// the provided context will unsubscribe from service session events.
//
// The storage implementation is responsible for ensuring that the channel is not
// interrupted by network errors, etc. The channel should only be closed
// when the context is cancelled.
SubscribeToServiceSessions(ctx context.Context) <-chan *ServiceSessionEvent
}
type ServiceSessionEvent ¶
type ServiceSessionEvent struct {
// Identifier is the service session's unique identifier
Identifier string
// Deleted indicates whether the service session was deleted
Deleted bool
// ServiceSession is the service session that was created or updated.
// If the service session was deleted, this will be nil
ServiceSession *servicesession.ServiceSession
}
ServiceSessionEvent is the event that is triggered when a service session is created, updated, or deleted
type Session ¶
type Session interface {
// SetSession sets the session for the given session.ID. If there is an error
// while setting the session, an error is returned.
// If the user or organization does not exist, ErrNotFound is returned.
// If the organization associated with the session is not empty, the session is
// associated with the organization. If the session is associated with an organization
// and that organization is deleted, the session should also be deleted. If the session
// already exists, it ErrAlreadyExists is returned.
SetSession(ctx context.Context, session *session.Session) error
// GetSession gets the session for the given id. If there is an error
// while getting the session, an error is returned. If the session does not
// exist, ErrNotFound is returned.
GetSession(ctx context.Context, id string) (*session.Session, error)
// ListSessions returns a list of all sessions. If there is an error while
// listing the sessions, an error is returned.
// If there is no error, the list of sessions is returned.
ListSessions(ctx context.Context) ([]*session.Session, error)
// DeleteSession deletes the session for the given id. If
// there is an error while deleting the session, an error is returned.
// ErrNotFound is returned if the session does not exist.
DeleteSession(ctx context.Context, id string) error
// UpdateSessionExpiry updates the expiry of the session for the given id. If
// there is an error while updating the session, an error is returned. If the
// session does not exist, ErrNotFound is returned.
UpdateSessionExpiry(ctx context.Context, id string, expiry time.Time) error
// SubscribeToSessions subscribes to session events. When a session is created,
// updated, or deleted, the event is emitted on the given channel. Cancelling
// the provided context will unsubscribe from session events.
SubscribeToSessions(ctx context.Context) <-chan *SessionEvent
}
Session is the interface for storage of sessions.
type SessionEvent ¶
type SessionEvent struct {
// Identifier is the session's unique identifier
Identifier string
// Deleted indicates whether the session was deleted
Deleted bool
// Session is the session that was created or updated.
// If the session was deleted, this will be nil
Session *session.Session
}
SessionEvent is the event that is triggered when a session is created, updated, or deleted
type Storage ¶
type Storage interface {
User
Registration
SecretKey
Session
APIKey
ServiceKey
ServiceSession
Flow
Health
Shutdown() error
}
Storage is the interface that must be implemented by the application using this auth library for authentication and session handling.
type User ¶
type User interface {
// UserExists verifies whether the given identifier exists. If there is an error
// while checking if the user exists, an error is returned, otherwise
// the boolean indicates whether the user exists. An error should not be
// returned if the user does not exist.
UserExists(ctx context.Context, identifier string) (bool, error)
// UserOrganizationExists verifies whether the given user identifier is part of the
// given organization. If there is an error while checking if the user is
// part of the organization, an error is returned, otherwise the boolean indicates
// whether the user is part of the organization. An error should not be
// returned if the user is not part of the organization, if the organization
// does not exist, or if the user does not exist - instead, the boolean
// should be false.
UserOrganizationExists(ctx context.Context, identifier string, organization string) (bool, error)
// UserDefaultOrganization returns the default organization for the given user
// identifier. If there is an error while getting the default organization,
// an error is returned, otherwise the organization is returned. If the user does not exist
// ErrNotFound is returned. If the user does not have a default organization,
// ErrNotFound is returned.
UserDefaultOrganization(ctx context.Context, identifier string) (string, error)
// NewUser creates a new user with the given claims. If the user already
// exists, ErrAlreadyExists is returned. If the user does not exist, the user is
// created and the claims are set. If there is an error while creating the
// user, an error is returned.
NewUser(ctx context.Context, claims *claims.Claims) error
}
User is the interface that must be implemented to store user data.