Documentation
¶
Overview ¶
Package emailpassword orchestrates email and password authentication.
Index ¶
- Variables
- func NormalizeEmail(rawEmail string) (string, error)
- type AddPasswordInput
- type Attempt
- type AttemptGuard
- type ChangePasswordInput
- type Config
- type CredentialStore
- type EmailNormalizer
- type EventType
- type LoginInput
- type LoginResult
- type Manager
- func (manager *Manager) AddPassword(ctx context.Context, input AddPasswordInput) (User, error)
- func (manager *Manager) ChangePassword(ctx context.Context, input ChangePasswordInput) (User, error)
- func (manager *Manager) Login(ctx context.Context, input LoginInput) (LoginResult, error)
- func (manager *Manager) Register(ctx context.Context, input RegisterInput) (User, error)
- func (manager *Manager) RemovePassword(ctx context.Context, input RemovePasswordInput) error
- type Operation
- type PasswordCredential
- type PasswordValidator
- type Passwords
- type RegisterInput
- type Registration
- type RemovePasswordInput
- type SecurityEvent
- type SecurityEventSink
- type Store
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrAttemptBlocked = errors.New("authentication attempt blocked") ErrConflict = errors.New("email/password conflict") ErrInvalidConfig = errors.New("invalid email/password configuration") ErrInvalidCredentials = errors.New("invalid email or password") ErrInvalidInput = errors.New("invalid email/password input") ErrInvalidPassword = errors.New("invalid password") ErrInvalidRecord = errors.New("invalid email/password record") ErrLastCredential = errors.New("cannot remove the last sign-in method") ErrNotFound = errors.New("email identity not found") ErrPasswordUnchanged = errors.New("new password matches current password") )
Functions ¶
func NormalizeEmail ¶
Types ¶
type AddPasswordInput ¶
type AttemptGuard ¶
type ChangePasswordInput ¶
type Config ¶
type Config struct {
Passwords Passwords
Credentials CredentialStore
ValidatePassword PasswordValidator
AttemptGuard AttemptGuard
SecurityEvents SecurityEventSink
NormalizeEmail EmailNormalizer
Now func() time.Time
}
type CredentialStore ¶
type CredentialStore interface {
FindBySubject(ctx context.Context, subjectID string) (User, PasswordCredential, error)
AddPassword(ctx context.Context, subjectID, passwordHash string, addedAt time.Time) (User, error)
ReplacePasswordHash(
ctx context.Context,
userID string,
currentHash string,
replacementHash string,
updatedAt time.Time,
) error
RemovePassword(ctx context.Context, subjectID, currentHash string, removedAt time.Time) error
}
CredentialStore makes account credential writes atomic and preserves another sign-in method on removal.
type EmailNormalizer ¶
type EmailNormalizer = emailaddress.Normalizer
type EventType ¶
type EventType string
const ( EventRegistrationRejected EventType = "registration_rejected" EventRegistrationSucceeded EventType = "registration_succeeded" EventLoginFailed EventType = "login_failed" EventLoginSucceeded EventType = "login_succeeded" EventPasswordAdded EventType = "password_added" EventPasswordChangeFailed EventType = "password_change_failed" EventPasswordChanged EventType = "password_changed" EventPasswordRemovalFailed EventType = "password_removal_failed" EventPasswordRemoved EventType = "password_removed" EventPasswordRehashed EventType = "password_rehashed" )
type LoginInput ¶
type LoginResult ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) AddPassword ¶
func (*Manager) ChangePassword ¶
func (*Manager) Login ¶
func (manager *Manager) Login(ctx context.Context, input LoginInput) (LoginResult, error)
Login returns the same credential error for unknown emails and wrong passwords.
func (*Manager) RemovePassword ¶
func (manager *Manager) RemovePassword(ctx context.Context, input RemovePasswordInput) error
type PasswordCredential ¶
type PasswordValidator ¶
type Passwords ¶
type Passwords interface {
Hash(plainPassword string) (string, error)
Verify(plainPassword, encodedHash string) (passwordhash.Verification, error)
}
type RegisterInput ¶
type Registration ¶
type RemovePasswordInput ¶
type SecurityEvent ¶
type SecurityEventSink ¶
type SecurityEventSink interface {
Record(ctx context.Context, event SecurityEvent)
}
type Store ¶
type Store interface {
Register(ctx context.Context, registration Registration) (User, error)
FindByEmail(ctx context.Context, normalizedEmail string) (User, PasswordCredential, error)
ReplacePasswordHash(
ctx context.Context,
userID string,
currentHash string,
replacementHash string,
updatedAt time.Time,
) error
}