| id | authentication | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| title | Authentication — password login, sessions, password recovery and account security | ||||||||||
| status | draft | ||||||||||
| created_at | 2026-09-11 | ||||||||||
| updated_at | 2026-09-11 | ||||||||||
| owner | TBD | ||||||||||
| affected_areas |
|
||||||||||
| tags |
|
The authentication feature is provided by the auth plugin (user.NewAuthPlugin, plugin name "auth") of the github.com/go-bolo/user module. It bundles the classic account-security building blocks of a Bolo application:
- Password login/logout with HTML pages and redirects (
/login,/logout,SessionController) and a JSON-friendly logout API (/auth/logout,AuthController) that also revokes OAuth2 tokens (see oauth2-password). - Redis-backed session authentication: a global Echo middleware loads the
uidstored in thesessioncookie, resolves theUserModel, and fillsRequestContext.IsAuthenticated,RequestContext.AuthenticatedUserand the user roles used by permission checks. - Password management: change own password (HTML +
/api/v2JSON), admin "set password" for a user (guarded by themanage_userspermission), and a three-step forgot-password flow based on one-timeauthtokensrecords. - Security helpers (package
user/security): a Redis-backed login throttle (LoginThrottle) and a Google reCAPTCHA v2/v3 verification client (ReCAPTCHA). - Auth email templates (
email-templates.go): account activation, reset password and change password notifications registered in theemailsplugin at bootstrap.
The plugin also registers the route for Facebook app-code login (POST /auth/facebook/app-login-code), whose internals belong to the facebook-auth feature.
-
Register the plugin in the Bolo app (as done in
setup_test.go):app.RegisterPlugin(user.NewAuthPlugin(&user.AuthPluginCfgs{ ResetPrefixNames: map[string]string{ /* optional custom reset page prefixes */ }, }))
-
Point the session Redis at
SITE_SESSION_ADDR_WRITER/SITE_SESSION_ADDR_READER(and optionallySITE_SESSION_PASSWORD,SITE_CACHE_DB). The plugin creates the session store on thebindMiddlewaresevent and installssession.Middlewareplus the session authentication middleware globally. -
Log a user in by posting
email(username or e-mail),passwordand optionalremember_meto/login; on success a Redis-backedsessioncookie holdinguidis set and the user is redirected to/. -
Log out with
GET/POST /logout(cookie-session only) orPOST /auth/logout(optionally sendingAuthorization: Bearer <access token>and/orX-Refresh-Token: <refresh token>to also revoke OAuth2 tokens). -
Recover a password:
GET/POST /auth/forgot-password(step 1, sends theAuthResetPasswordEmailwith a reset URL), open/auth/:userID/forgot-password/reset?t=<token>(step 2, validates the token), thenPOST /api/v2/auth/forgot-password/process(step 3, sets the new password and consumes the token). -
Change the own password via
/auth/change-password(HTML) orPOST /api/v2/auth/change-password(JSON, requires an authenticated user). -
Use
user/securitybuilding blocks from host applications:throttle := security.NewLoginThrottle(app) if ok, _ := throttle.CanLogin(userID, c); ok { /* allow attempt */ } captcha, _ := security.NewReCAPTCHA(secret, security.V3, 10*time.Second) err := captcha.VerifyWithOptions(response, security.VerifyOption{Action: "login", RemoteIP: c.RealIP()})
Note: inside this module these helpers are not yet wired into any HTTP handler; they are exercised only by their unit tests.
- Authenticate requests coming from browser cookie sessions and expose the authenticated user/roles to the whole request pipeline.
- Provide password login/logout endpoints compatible with both HTML form flows and JSON clients.
- Provide safe, single-use password recovery using one-time tokens stored in the
authtokenstable. - Notify users by e-mail on password changes and reset requests, using templates registered in the
emailsplugin. - Offer reusable primitives (login throttling, reCAPTCHA verification) to harden login flows.
- Keep compatibility with legacy We.js clients (e.g.
POST /auth/:userID/new-password).
- backend:
AuthPlugin,AuthController,SessionController,auth_session.go/session.go,middlewares.go,handlers.go(user settings JSON glue),models/PasswordModel.go,models/AuthTokenModel.go,security/loginThrottle.go,security/recaptcha.go,email-templates.go,install.go,flash.go. - http-api: routes under
/login,/logout,/auth/*and/api/v2/auth/*(see the API contract in spec.md); global session middleware applied to every route. - data:
passwords,authtokenstables (created by the module init migration); Redis keys for sessions and login-throttle counters.
[authentication, login, sessions, password-reset, throttling, recaptcha, redis, email, backend, http-api]
- Feature spec: spec.md
- Changelog: changelog.md
- OAuth2 password grant (token login used by SPAs/tests): ../oauth2-password/guide.md
- OAuth2 JWT: ../oauth2-jwt/guide.md
- Facebook authentication (route registered here, details there): ../facebook-auth/guide.md
- Sessions deep-dive: ../sessions/guide.md
- Users feature (user model, CRUD,
/user-settings): ../user-management/guide.md - Module README: ../../README.md