Documentation
¶
Index ¶
- Constants
- Variables
- func Actions() []string
- func ApplyPasswordRules(rules []PasswordRule, password string, user *User) error
- func Codename(resource, action string) string
- func CommonPasswords() []string
- func HashPassword(password string) (string, error)
- func LooksHashed(encoded string) bool
- func Matches(u *User, term string) bool
- func Prepare(u *User)
- func SplitCodename(codename string) (resource, action string, ok bool)
- func TokenDigest(plain string) string
- func ValidatePassword(password string) error
- func ValidatePasswordLength(password string, minLength int) error
- func VerifyPassword(password, encoded string) bool
- type Hasher
- type LoginLimiter
- type MemoryStore
- func (m *MemoryStore) All(_ context.Context) ([]*User, error)
- func (m *MemoryStore) ByEmail(_ context.Context, email string) (*User, error)
- func (m *MemoryStore) ByID(_ context.Context, id string) (*User, error)
- func (m *MemoryStore) ByUsername(_ context.Context, username string) (*User, error)
- func (m *MemoryStore) Count(_ context.Context) (int, error)
- func (m *MemoryStore) CountActiveSuperadmins(_ context.Context) (int, error)
- func (m *MemoryStore) Create(_ context.Context, u *User) error
- func (m *MemoryStore) Delete(_ context.Context, id string) error
- func (m *MemoryStore) Recent(ctx context.Context, n int) ([]*User, error)
- func (m *MemoryStore) Search(ctx context.Context, term string, limit, offset int) ([]*User, int, error)
- func (m *MemoryStore) Stats(ctx context.Context) (Stats, error)
- func (m *MemoryStore) Update(_ context.Context, u *User) error
- type NewUser
- type Options
- type PasswordChange
- type PasswordRule
- type Permission
- type PermissionStore
- type ResetToken
- type Role
- type RolePermission
- type Service
- func (s *Service) AllowsPasswordChange() bool
- func (s *Service) Authenticate(ctx context.Context, username, password string) (*User, error)
- func (s *Service) AuthenticateRequest(r *http.Request, username, password string) (*User, error)
- func (s *Service) Can(r *http.Request, codename string) bool
- func (s *Service) CanAny(r *http.Request, codenames ...string) bool
- func (s *Service) ChangePassword(r *http.Request, in PasswordChange) error
- func (s *Service) CheckResetToken(ctx context.Context, plain string) (*User, error)
- func (s *Service) CreateResetToken(ctx context.Context, userID string) (string, error)
- func (s *Service) CreateSuperadmin(ctx context.Context, username, email, password string) (*User, error)
- func (s *Service) CreateUser(ctx context.Context, in NewUser) (*User, error)
- func (s *Service) CurrentUser(r *http.Request) *User
- func (s *Service) GrantedTo(ctx context.Context, userID string) ([]string, error)
- func (s *Service) HashPassword(password string) (string, error)
- func (s *Service) Login(r *http.Request, u *User) error
- func (s *Service) Logout(r *http.Request) error
- func (s *Service) Middleware(next http.Handler) http.Handler
- func (s *Service) MinPasswordLength() int
- func (s *Service) PasswordRules() []PasswordRule
- func (s *Service) Permissions() PermissionStore
- func (s *Service) RequireLogin(loginURL string) func(http.Handler) http.Handler
- func (s *Service) RequirePermission(codename string) func(http.Handler) http.Handler
- func (s *Service) RequireStaff(loginURL string) func(http.Handler) http.Handler
- func (s *Service) RequireSuperadmin(loginURL string) func(http.Handler) http.Handler
- func (s *Service) ResetPassword(ctx context.Context, userID string, in PasswordChange) error
- func (s *Service) RevokeOtherSessions(r *http.Request) int
- func (s *Service) SetPassword(ctx context.Context, id, password string) error
- func (s *Service) Tokens() TokenStore
- func (s *Service) UseResetToken(ctx context.Context, plain string, in PasswordChange) (*User, error)
- func (s *Service) Users() Store
- func (s *Service) ValidatePassword(password string) error
- func (s *Service) ValidatePasswordFor(password string, user *User) error
- type Stats
- type Store
- type SuperadminCounter
- type SyncReport
- type ThrottlePolicy
- type TokenStore
- type User
- type UserRole
Constants ¶
View Source
const ( DefaultIterations = 600000 DefaultMinPasswordLen = 8 MaxPasswordLength = 1024 )
View Source
const ( ActionCreate = "create" ActionRead = "read" ActionUpdate = "update" ActionDelete = "delete" )
Variables ¶
View Source
var ( ErrPasswordMismatch = errors.New("coyote/auth: the new passwords do not match") ErrWrongPassword = errors.New("coyote/auth: the current password is not right") ErrChangeDisabled = errors.New("coyote/auth: password changes are turned off") )
View Source
var ( ErrUserNotFound = errors.New("coyote/auth: user not found") ErrUserExists = errors.New("coyote/auth: username already taken") ErrEmailExists = errors.New("coyote/auth: email already registered") ErrInvalidUser = errors.New("coyote/auth: invalid username") ErrInvalidEmail = errors.New("coyote/auth: invalid email address") ErrLastSuperadmin = errors.New("coyote/auth: cannot remove the last superadmin") )
View Source
var ( ErrInvalidHash = errors.New("coyote/auth: malformed password hash") ErrPasswordTooShort = errors.New("coyote/auth: password is too short") ErrPasswordTooLong = errors.New("coyote/auth: password is too long") ErrPasswordRejected = errors.New("coyote/auth: password rejected") )
View Source
var ( ErrPasswordNumericOnly = errors.New("coyote/auth: password is entirely numeric") ErrPasswordSimilar = errors.New("coyote/auth: password is too similar to the account details") ErrPasswordCommon = errors.New("coyote/auth: password is one of the most commonly used") )
View Source
var ( ErrInvalidCredentials = errors.New("coyote/auth: invalid username or password") ErrInactiveAccount = errors.New("coyote/auth: account is disabled") )
View Source
var ( ErrTokenInvalid = errors.New("coyote/auth: reset token is unknown, used or expired") ErrNoTokenStore = errors.New("coyote/auth: no reset token store configured") )
View Source
var ErrTooManyAttempts = errors.New("coyote/auth: too many failed sign-in attempts")
Functions ¶
func ApplyPasswordRules ¶
func ApplyPasswordRules(rules []PasswordRule, password string, user *User) error
func CommonPasswords ¶
func CommonPasswords() []string
func HashPassword ¶
func LooksHashed ¶
func SplitCodename ¶
func TokenDigest ¶
func ValidatePassword ¶
func ValidatePasswordLength ¶
func VerifyPassword ¶
Types ¶
type Hasher ¶
type Hasher struct {
Iterations int
}
func DefaultHasher ¶
func DefaultHasher() Hasher
func (Hasher) NeedsRehash ¶
type LoginLimiter ¶
func NewLoginLimiter ¶
func NewLoginLimiter(policy ThrottlePolicy) LoginLimiter
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
func (*MemoryStore) ByUsername ¶
func (*MemoryStore) CountActiveSuperadmins ¶
func (m *MemoryStore) CountActiveSuperadmins(_ context.Context) (int, error)
type Options ¶
type Options struct {
Hasher Hasher
MinPasswordLength int
PasswordRules []PasswordRule
Throttle ThrottlePolicy
Limiter LoginLimiter
TrustedProxyCount int
PermissionStore PermissionStore
AllowChange bool
Tokens TokenStore
TokenLifetime time.Duration
}
type PasswordChange ¶
type PasswordRule ¶
func DefaultPasswordRules ¶
func DefaultPasswordRules(minLength int) []PasswordRule
func MinimumLength ¶
func MinimumLength(minLength int) PasswordRule
func NotCommon ¶
func NotCommon(list []string) PasswordRule
func NotEntirelyNumeric ¶
func NotEntirelyNumeric() PasswordRule
func NotSimilarToAccount ¶
func NotSimilarToAccount() PasswordRule
type Permission ¶
type Permission struct {
ID string `gorm:"primaryKey;size:64"`
Resource string `gorm:"uniqueIndex:idx_permission_codename;size:100;not null"`
Action string `gorm:"uniqueIndex:idx_permission_codename;size:20;not null"`
Label string `gorm:"size:150"`
CreatedAt time.Time
}
func PermissionsFor ¶
func PermissionsFor(resource string) []Permission
func (Permission) Codename ¶
func (p Permission) Codename() string
func (Permission) TableName ¶
func (Permission) TableName() string
type PermissionStore ¶
type PermissionStore interface {
SyncPermissions(ctx context.Context, resources []string) (SyncReport, error)
AllPermissions(ctx context.Context) ([]Permission, error)
CodenamesForUser(ctx context.Context, userID string) ([]string, error)
AllRoles(ctx context.Context) ([]Role, error)
RoleByID(ctx context.Context, id string) (*Role, error)
CreateRole(ctx context.Context, role *Role) error
UpdateRole(ctx context.Context, role *Role) error
DeleteRole(ctx context.Context, id string) error
RolePermissions(ctx context.Context, roleID string) ([]string, error)
SetRolePermissions(ctx context.Context, roleID string, permissionIDs []string) error
RolesForUser(ctx context.Context, userID string) ([]string, error)
SetUserRoles(ctx context.Context, userID string, roleIDs []string) error
}
type ResetToken ¶
type ResetToken struct {
Digest string `gorm:"primaryKey;size:64"`
UserID string `gorm:"index;size:64;not null"`
CreatedAt time.Time
ExpiresAt time.Time `gorm:"index"`
UsedAt *time.Time
}
func (ResetToken) TableName ¶
func (ResetToken) TableName() string
type Role ¶
type RolePermission ¶
type RolePermission struct {
RoleID string `gorm:"primaryKey;size:64"`
PermissionID string `gorm:"primaryKey;size:64"`
}
func (RolePermission) TableName ¶
func (RolePermission) TableName() string
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) AllowsPasswordChange ¶
func (*Service) Authenticate ¶
func (*Service) AuthenticateRequest ¶
func (*Service) ChangePassword ¶
func (s *Service) ChangePassword(r *http.Request, in PasswordChange) error
func (*Service) CheckResetToken ¶
func (*Service) CreateResetToken ¶
func (*Service) CreateSuperadmin ¶
func (*Service) CreateUser ¶
func (*Service) MinPasswordLength ¶
func (*Service) PasswordRules ¶
func (s *Service) PasswordRules() []PasswordRule
func (*Service) Permissions ¶
func (s *Service) Permissions() PermissionStore
func (*Service) RequireLogin ¶
func (*Service) RequirePermission ¶
func (*Service) RequireStaff ¶
func (*Service) RequireSuperadmin ¶
func (*Service) ResetPassword ¶
func (*Service) SetPassword ¶
func (*Service) Tokens ¶
func (s *Service) Tokens() TokenStore
func (*Service) UseResetToken ¶
func (*Service) ValidatePassword ¶
type Store ¶
type Store interface {
ByID(ctx context.Context, id string) (*User, error)
ByUsername(ctx context.Context, username string) (*User, error)
ByEmail(ctx context.Context, email string) (*User, error)
Create(ctx context.Context, u *User) error
Update(ctx context.Context, u *User) error
Delete(ctx context.Context, id string) error
All(ctx context.Context) ([]*User, error)
Search(ctx context.Context, term string, limit, offset int) ([]*User, int, error)
Recent(ctx context.Context, n int) ([]*User, error)
Count(ctx context.Context) (int, error)
Stats(ctx context.Context) (Stats, error)
}
type SuperadminCounter ¶
type SyncReport ¶
func (SyncReport) Empty ¶
func (r SyncReport) Empty() bool
type ThrottlePolicy ¶
type TokenStore ¶
type TokenStore interface {
Save(ctx context.Context, token ResetToken) error
ByDigest(ctx context.Context, digest string) (ResetToken, error)
MarkUsed(ctx context.Context, digest string, at time.Time) error
DeleteForUser(ctx context.Context, userID string) error
Sweep(ctx context.Context, before time.Time) (int, error)
}
type User ¶
type User struct {
ID string `gorm:"primaryKey;size:64"`
FirstName string
LastName string
Email string `gorm:"index;size:320"`
Username string `gorm:"uniqueIndex;size:64;not null"`
Password string `gorm:"not null"`
IsActive bool `gorm:"index;default:true"`
IsStaff bool `gorm:"index"`
IsSuperadmin bool `gorm:"index"`
LastLoginAt time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
func (*User) CanReachAdmin ¶
func (*User) DisplayName ¶
func (*User) HasLoggedIn ¶
func (*User) HasUsablePassword ¶
Click to show internal directories.
Click to hide internal directories.