Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ross/docs/docs/api-variants.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ The following configuration demonstrates a complete setup featuring multi-versio
"type": "up-auth",
"config": {
"fields": {
"usernameField": "email",
"passwordField": "password"
"emailField": "email",
"passwordField": "password",
"isVerifiedField": "is_active"
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions ross/docs/docs/authentication/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ Authentication lives at the top level of your configuration file:
"type": "up-auth",
"config": {
"fields": {
"usernameField": "email",
"passwordField": "password"
"emailField": "email",
"passwordField": "password",
"isVerifiedField": "is_active"
}
}
},
Expand Down Expand Up @@ -276,10 +277,10 @@ Auth routes are mounted under the API prefix and variant, so the default base pa
| `POST /auth/login` | `up-auth` |
| `POST /auth/change-password` | `up-auth` |
| `GET`, `PATCH`, `DELETE /auth/user/me` | `up-auth` (these routes also serve SSO-owned rows in a mixed deployment) |
| `PATCH /auth/user/email` | `up-auth` + `fields.isVerifiedField` |
| `PATCH /auth/user/email` | `up-auth` |
| `POST /auth/forgot-password` and its `verify/otp` and `resend/otp` routes | `up-auth` + `integrations.email` |
| `POST /auth/login/verify/otp` and `/login/resend/otp` | `up-auth` + `mfaRequired: true` |
| `POST /auth/register/verify/otp` and `/register/resend/otp` | `up-auth` + `fields.isVerifiedField` |
| `POST /auth/register/verify/otp` and `/register/resend/otp` | `up-auth` |
| `GET /auth/sso/<name>/login` and `.../callback` | Each SSO provider |
| `POST /auth/sso/<name>/token` | An SSO provider with `redirectUrl` |
| `GET /auth/sso/<name>/metadata` | A SAML provider |
Expand Down
57 changes: 24 additions & 33 deletions ross/docs/docs/authentication/up-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ This is the only provider that owns a password. It also provides registration, p
"type": "up-auth",
"config": {
"fields": {
"usernameField": "email",
"passwordField": "password"
"emailField": "email",
"passwordField": "password",
"isVerifiedField": "is_active"
}
}
}
Expand All @@ -43,18 +44,18 @@ This is the only provider that owns a password. It also provides registration, p
| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `"up-auth"` | **Yes** | — | Provider identifier. |
| `config.fields.usernameField` | `string` | **Yes** | — | Model column used as the login identifier. It is also the address OTP emails are sent to. |
| `config.fields.emailField` | `string` | **Yes** | — | Model column used as the login identifier. It is also the address OTP emails are sent to. |
| `config.fields.passwordField` | `string` | **Yes** | — | Model column that stores the bcrypt hash. Mark it `"secret": true`. |
| `config.fields.isVerifiedField` | `string` | No | — | Boolean model column used for email verification. When set, registration starts unverified and login rejects unverified users. Requires `integrations.email`. |
| `config.fields.isVerifiedField` | `string` | **Yes** | — | Boolean model column used for email verification. Registration starts unverified and login rejects unverified users. Requires `integrations.email`. |
| `config.mfaRequired` | `boolean` | No | `false` | Sends an OTP after a correct password and withholds the access token until the OTP is verified. Requires `integrations.email`. |

Additional rules enforced at startup:

- At most one `up-auth` provider is allowed.
- `userModel` and `jwtSecret` are required.
- `usernameField` and `passwordField` must exist in the user model and be of type `string`.
- When no SSO provider is configured, `usernameField` must be unique (`unique: true` or unique index) and not nullable (`nullable: false`), and `passwordField` must not be nullable (`nullable: false`).
- When an SSO provider is configured in the same application, `passwordField` must be `nullable: true` (and `usernameField` must be `nullable: true` unless mapped/provided), because SSO accounts do not have passwords.
- `emailField` and `passwordField` must exist in the user model and be of type `string`.
- When no SSO provider is configured, `emailField` must be unique (`unique: true` or unique index) and not nullable (`nullable: false`), and `passwordField` must not be nullable (`nullable: false`).
- When an SSO provider is configured in the same application, `passwordField` must be `nullable: true` (and `emailField` must be `nullable: true` unless mapped/provided), because SSO accounts do not have passwords.
- `isVerifiedField` must exist, must be of type `boolean`, and requires `integrations.email`.
- `mfaRequired: true` requires `integrations.email`.

Expand All @@ -72,13 +73,13 @@ All routes are mounted under the API prefix and variant, so the default base pat
| `POST` | `/api/v1/auth/login` | No | `up-auth` configured |
| `POST` | `/api/v1/auth/login/verify/otp` | No | `mfaRequired: true` |
| `POST` | `/api/v1/auth/login/resend/otp` | No | `mfaRequired: true` |
| `POST` | `/api/v1/auth/register/verify/otp` | No | `isVerifiedField` set |
| `POST` | `/api/v1/auth/register/resend/otp` | No | `isVerifiedField` set |
| `POST` | `/api/v1/auth/register/verify/otp` | No | `up-auth` configured |
| `POST` | `/api/v1/auth/register/resend/otp` | No | `up-auth` configured |
| `POST` | `/api/v1/auth/forgot-password` | No | `integrations.email` |
| `POST` | `/api/v1/auth/forgot-password/verify/otp` | No | `integrations.email` |
| `POST` | `/api/v1/auth/forgot-password/resend/otp` | No | `integrations.email` |
| `POST` | `/api/v1/auth/change-password` | Bearer JWT | `up-auth` configured |
| `PATCH` | `/api/v1/auth/user/email` | Bearer JWT | `isVerifiedField` set |
| `PATCH` | `/api/v1/auth/user/email` | Bearer JWT | `up-auth` configured |
| `GET` | `/api/v1/auth/user/me` | Bearer JWT | `up-auth` configured |
| `PATCH` | `/api/v1/auth/user/me` | Bearer JWT | `up-auth` configured |
| `DELETE` | `/api/v1/auth/user/me` | Bearer JWT | `up-auth` configured |
Expand All @@ -103,24 +104,10 @@ The request body is generated from the user model:
- The primary key and managed timestamp columns are excluded.
- Every non-nullable field without a default is required.
- Unknown properties are rejected.
- When `isVerifiedField` is configured, that column is removed from the accepted body and forced to `false`.
- `isVerifiedField` is removed from the accepted body and forced to `false`.
- The password is hashed before the row is inserted.

Success (no verification configured):

```json
{
"code": 201,
"message": "Successfully registered a new user in the users table",
"data": {
"email": "alice@example.com",
"display_name": "Alice",
"provider": "up-auth"
}
}
```

Success with `isVerifiedField` configured:
Success:

```json
{
Expand Down Expand Up @@ -178,7 +165,7 @@ Complete the login with `POST /auth/login/verify/otp` and the `ulid`, `otp`, and
| --- | --- | --- |
| `400` | `Password management is not supported for accounts authenticated via <provider>...` | The matched row belongs to an SSO provider. |
| `401` | `Invalid username or password` | Unknown user or wrong password. |
| `401` | `User is not verified` | `isVerifiedField` is set and the column is not `true`. |
| `401` | `User is not verified` | The `isVerifiedField` column is not `true`. |
| `400` | Schema validation message | Missing or unknown body properties. |

The handler compares against a dummy hash when the user does not exist, so response timing does not reveal whether an account is registered.
Expand Down Expand Up @@ -315,7 +302,7 @@ The route always requires a bearer token, independently of the `apis` authorizat

## Change email

Available only when `fields.isVerifiedField` is configured. It updates the email column, marks the account unverified, and sends an OTP to the new address:
Updates the email column, marks the account unverified, and sends an OTP to the new address:

```http
PATCH /api/v1/auth/user/email
Expand Down Expand Up @@ -369,9 +356,9 @@ Content-Type: application/json
The accepted body is generated from the model with these columns removed:

- the primary key (`idField`)
- the username column (`usernameField`)
- the email column (`emailField`)
- the password column (`passwordField`)
- the verification column (`isVerifiedField`, when configured)
- the verification column (`isVerifiedField`)
- managed timestamp columns

An empty body returns `400 No editable fields provided`. Success returns the updated fields:
Expand Down Expand Up @@ -416,7 +403,7 @@ Deletion runs inside a transaction. The row is removed permanently; ROSS does no
| Claim | Source |
| --- | --- |
| `id` | `userModel.idField` |
| `<usernameField>` | The username column, when it has a value |
| `<emailField>` | The email column, when it has a value |
| `role` | `rbac.roleField` when RBAC is enabled and the value is a scalar |
| `roles` | `rbac.roleField` when the value is an array or a JSON-encoded array |
| `iat`, `exp` | Issued-at and `accessTokenExpiration` |
Expand Down Expand Up @@ -448,7 +435,7 @@ Deletion runs inside a transaction. The row is removed permanently; ROSS does no
"type": "up-auth",
"config": {
"fields": {
"usernameField": "email",
"emailField": "email",
"passwordField": "password",
"isVerifiedField": "is_active"
},
Expand Down Expand Up @@ -484,7 +471,11 @@ Password login and SSO can coexist. Make the credential columns nullable and let
{
"type": "up-auth",
"config": {
"fields": {"usernameField": "email", "passwordField": "password"}
"fields": {
"emailField": "email",
"passwordField": "password",
"isVerifiedField": "is_active"
}
}
},
{
Expand Down
12 changes: 5 additions & 7 deletions ross/docs/docs/integrations/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ ROSS sends email only for account and security flows that are driven by one-time
| --- | --- | --- |
| Forgot password | `POST /api/v1/auth/forgot-password`, `/forgot-password/verify/otp`, `/forgot-password/resend/otp` | `integrations.email` is configured |
| Login MFA | `POST /api/v1/auth/login`, `/login/verify/otp`, `/login/resend/otp` | `integrations.email` and the `up-auth` provider has `config.mfaRequired: true` |
| Registration verification | `POST /api/v1/auth/register`, `/register/verify/otp`, `/register/resend/otp` | `integrations.email` and the `up-auth` provider has `config.fields.isVerifiedField` set |
| Email change | `PATCH /api/v1/auth/user/email` | `integrations.email` and `config.fields.isVerifiedField` is set |
| Registration verification | `POST /api/v1/auth/register`, `/register/verify/otp`, `/register/resend/otp` | `integrations.email` and `up-auth` is configured |
| Email change | `PATCH /api/v1/auth/user/email` | `integrations.email` and `up-auth` is configured |

Each OTP email contains:

Expand All @@ -72,16 +72,14 @@ It depends on your authentication configuration:

| Your authentication setup | Email integration |
| --- | --- |
| Authentication disabled | Not needed |
| `up-auth` without `mfaRequired` and without `isVerifiedField` | Optional, but required for forgot-password |
| `up-auth` with `mfaRequired: true` | **Required** (validation fails otherwise) |
| `up-auth` with `config.fields.isVerifiedField` set | **Required** (validation fails otherwise) |
| Authentication disabled or SSO-only | Not needed |
| `up-auth` (with or without `mfaRequired: true`) | **Required** (validation fails otherwise) |

If you omit `integrations.email`:

- ROSS does not register the `communicate` plugin or the `app.communicate` decorator.
- Email-dependent routes are not mounted, so requests to them return `404 Not Found`.
- Configuration validation rejects `mfaRequired: true` and `isVerifiedField` with an explicit error that the integration must be configured.
- Configuration validation rejects `up-auth` (`isVerifiedField` and `mfaRequired: true`) with an explicit error that the integration must be configured.

## Secrets and environment variables

Expand Down
5 changes: 3 additions & 2 deletions ross/docs/docs/rbac.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ Here is an end-to-end example configuring models, authentication, role hierarchi
"type": "up-auth",
"config": {
"fields": {
"usernameField": "email",
"passwordField": "password"
"emailField": "email",
"passwordField": "password",
"isVerifiedField": "is_active"
}
}
}
Expand Down
25 changes: 20 additions & 5 deletions ross/e2e/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ const upAuthE2EConfig: AppConfigInput = {
},
},
},
integrations: {
email: {
provider: 'dummy',
},
},
authentication: {
enabled: true,
jwtSecret: 'e2e-up-auth-jwt-secret-at-least-32-chars-long!',
Expand All @@ -335,8 +340,9 @@ const upAuthE2EConfig: AppConfigInput = {
type: 'up-auth',
config: {
fields: {
usernameField: 'email',
emailField: 'email',
passwordField: 'password',
isVerifiedField: 'is_active',
},
},
},
Expand Down Expand Up @@ -369,6 +375,11 @@ const upAuthE2EConfig: AppConfigInput = {
type: 'string',
nullable: true,
},
is_active: {
type: 'boolean',
nullable: false,
default: false,
},
full_name: {
type: 'string',
nullable: true,
Expand Down Expand Up @@ -470,18 +481,22 @@ test.describe
expect(res.status()).toBe(400);
});

test('Successfully registers a new user without exposing secret password (HTTP 201)', async () => {
test('Successfully registers a new user and returns OTP challenge (HTTP 201)', async () => {
const res = await server.request.post('/api/v1/auth/register', {
data: testUser,
});
expect(res.status()).toBe(201);
const body = await res.json();
expect(body.code).toBe(201);
expect(body.data).toBeDefined();
expect(body.data.email).toBe(testUser.email);
expect(body.data.full_name).toBe(testUser.full_name);
expect(body.data.provider).toBe('up-auth');
expect(body.data.requiresMfa).toBe(true);
expect(typeof body.data.ulid).toBe('string');
expect(body.data.password).toBeUndefined();

await server.app.db.query(
'UPDATE users SET is_active = 1 WHERE email = ?;',
[testUser.email],
);
});

test('Rejects registration with duplicate email address (conflict)', async () => {
Expand Down
9 changes: 8 additions & 1 deletion ross/e2e/custom-endpoints.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const customEndpointsE2EConfig: AppConfigInput = {
engine: 'memory',
},
},
integrations: {
email: {
provider: 'dummy',
},
},
authentication: {
enabled: true,
jwtSecret: 'e2e-custom-endpoints-super-secret-jwt-key-min-32-chars!',
Expand All @@ -59,8 +64,9 @@ const customEndpointsE2EConfig: AppConfigInput = {
type: 'up-auth',
config: {
fields: {
usernameField: 'email',
emailField: 'email',
passwordField: 'password',
isVerifiedField: 'is_active',
},
},
},
Expand Down Expand Up @@ -99,6 +105,7 @@ const customEndpointsE2EConfig: AppConfigInput = {
password: {type: 'string', nullable: false, secret: true},
role: {type: 'string', nullable: false, default: 'viewer'},
provider: {type: 'string', nullable: true},
is_active: {type: 'boolean', default: true},
},
},
projects: {
Expand Down
12 changes: 11 additions & 1 deletion ross/e2e/delete-ssp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const deleteSspE2EConfig: AppConfigInput = {
},
},
},
integrations: {
email: {
provider: 'dummy',
},
},
authentication: {
enabled: true,
jwtSecret: 'super-secret-jwt-key-for-delete-ssp-testing-32chars',
Expand All @@ -30,8 +35,9 @@ const deleteSspE2EConfig: AppConfigInput = {
type: 'up-auth',
config: {
fields: {
usernameField: 'email',
emailField: 'email',
passwordField: 'password',
isVerifiedField: 'is_active',
},
},
},
Expand Down Expand Up @@ -61,6 +67,10 @@ const deleteSspE2EConfig: AppConfigInput = {
type: 'string',
nullable: true,
},
is_active: {
type: 'boolean',
default: true,
},
},
},
todos: {
Expand Down
Loading
Loading