localauth

package
v0.28.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 27 Imported by: 0

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

View Source
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

View Source
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

func HashPassword(password string) (string, error)

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

func VerifyPassword(encodedHash, password string) error

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

func (InvalidUserError) Localized added in v0.27.0

func (e InvalidUserError) Localized(locale string) string

Localized returns a user-facing validation message in the request locale.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

func New

func New(gatewayClient *client.Client, serverURL string) (*Provider, error)

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

func (p *Provider) DeleteUser(ctx context.Context, id uint) error

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) GetUser

func (p *Provider) GetUser(ctx context.Context, id uint) (*types.LocalAuthUser, error)

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.

func (*Provider) SetSessionCookie added in v0.26.0

func (p *Provider) SetSessionCookie(w http.ResponseWriter, token string, expiresAt time.Time)

func (*Provider) Start

func (p *Provider) Start(ctx context.Context) (url.URL, error)

Start serves the provider on a random loopback port and returns its URL. The server is shut down when the context is cancelled.

func (*Provider) Users

func (p *Provider) Users(ctx context.Context) ([]types.LocalAuthUser, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL