Documentation
¶
Overview ¶
Package localauth implements a built-in username/password auth provider.
Unlike the other auth providers, which are external binaries launched as daemons by the dispatcher, this provider runs in-process so that it can share Obot's database. It speaks the same HTTP protocol as the external providers (/oauth2/start, /oauth2/callback, /oauth2/sign_out, /obot-get-state, /obot-get-user-info), so the rest of the auth stack treats it like any other.
Index ¶
- Constants
- Variables
- func AuthProvider() *v1.AuthProvider
- func HashPassword(password string) (string, error)
- func VerifyPassword(encodedHash, password string) error
- type InvalidUserError
- type Provider
- func (p *Provider) ActivateInitialOwner(ctx context.Context, setupToken string) (string, time.Time, error)
- func (p *Provider) ChangePassword(ctx context.Context, id uint, password, currentSessionID string) error
- func (p *Provider) CreateUser(ctx context.Context, email, password string, ...) (*types.LocalAuthUser, error)
- func (p *Provider) DeleteUser(ctx context.Context, id uint) error
- func (p *Provider) EnsureInitialOwner(ctx context.Context, email, setupToken string, setupTokenExpiresAt time.Time) error
- func (p *Provider) GetUser(ctx context.Context, id uint) (*types.LocalAuthUser, error)
- func (p *Provider) SetPassword(ctx context.Context, id uint, password string, requirePasswordChange bool) error
- func (p *Provider) SetSessionCookie(w http.ResponseWriter, token string, expiresAt time.Time)
- func (p *Provider) Start(ctx context.Context) (url.URL, error)
- func (p *Provider) Users(ctx context.Context) ([]types.LocalAuthUser, error)
Constants ¶
const ( // ProviderName is the name of the AuthProvider resource for this provider. ProviderName = system.LocalAuthProvider // EmailDomainsEnvVar is the configuration parameter that restricts which email domains // can be used for local users. It matches the name used by the external auth providers. EmailDomainsEnvVar = "OBOT_AUTH_PROVIDER_EMAIL_DOMAINS" // LoginPath is the UI route that renders the login form. LoginPath = "/login/local" // ChangePasswordPath is the page a restricted local-auth session is sent to; it may otherwise // only use the activation page. ChangePasswordPath = "/change-password" )
Variables ¶
var ( // ErrInvalidPassword is returned when a password does not match its hash. ErrInvalidPassword = errors.New("invalid password") )
Functions ¶
func AuthProvider ¶
func AuthProvider() *v1.AuthProvider
AuthProvider returns the AuthProvider resource for the built-in local auth provider. It has no Command: the dispatcher serves it from within the Obot process instead of launching a daemon for it.
func HashPassword ¶
HashPassword hashes a plaintext password with argon2id and returns it in the PHC string format, which carries the parameters and salt alongside the derived key.
func VerifyPassword ¶
VerifyPassword checks a plaintext password against a PHC-encoded argon2id hash. It returns ErrInvalidPassword if the password does not match.
Types ¶
type InvalidUserError ¶
type InvalidUserError struct {
// contains filtered or unexported fields
}
InvalidUserError is returned when a local user cannot be created or updated as requested. It is a user error, not a server error: the message is safe to return to the caller.
func (InvalidUserError) Error ¶
func (e InvalidUserError) Error() string
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
func (*Provider) ActivateInitialOwner ¶ added in v0.26.0
func (p *Provider) ActivateInitialOwner(ctx context.Context, setupToken string) (string, time.Time, error)
ActivateInitialOwner validates a setup token and starts a restricted session for the account it was bound to. The token stays reusable until password completion or expiry, and an invalid one tells the caller nothing about the account.
func (*Provider) ChangePassword ¶ added in v0.26.0
func (p *Provider) ChangePassword(ctx context.Context, id uint, password, currentSessionID string) error
ChangePassword lets an authenticated local user choose their own password. The current session is preserved, every other session is invalidated, and the login restriction is cleared.
func (*Provider) CreateUser ¶
func (p *Provider) CreateUser(ctx context.Context, email, password string, requirePasswordChange, bootstrap bool) (*types.LocalAuthUser, error)
CreateUser creates a local user with the given email and plaintext password.
func (*Provider) DeleteUser ¶
DeleteUser removes a local user and their sessions. It does not delete the Obot user that the local user logged in as: that is managed from the Users page like any other user.
func (*Provider) EnsureInitialOwner ¶ added in v0.26.0
func (p *Provider) EnsureInitialOwner(ctx context.Context, email, setupToken string, setupTokenExpiresAt time.Time) error
EnsureInitialOwner configures the local provider and creates the initial owner exactly once. A pending setup token may be rotated, but a completed account is never rearmed from the environment.
func (*Provider) SetPassword ¶
func (p *Provider) SetPassword(ctx context.Context, id uint, password string, requirePasswordChange bool) error
SetPassword sets a local user's password, which also signs them out everywhere.