@xeplr/auth 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/userRoles.js +7 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ Everything in `requiredEnv`, plus a connection. `requiredEnv` includes the sign-
|
|
|
116
116
|
| `XEPLR_AUTH_MIGRATIONS` | none | comma-separated app migration directories, run after auth's own — [details](#migrations) |
|
|
117
117
|
| `AUTH_TENANT_HEADER` | — | the header that names the company a role is created in (e.g. `x-company-id`), or `none` for a single-tenant app. No default: a multi-tenant app that forgot it would make every role visible to every company — [details](#roles-belong-to-a-company) |
|
|
118
118
|
| `AUTH_ACTIVATION_URL` | — | full address of your activation page, e.g. `http://localhost:19100/auth/activate`; `?token=…` is appended. The older `AUTH_ACTIVATION_BASE_URL` (below) also satisfies it — `requiredEnv.activationLinkVar` names whichever the install uses. Without it registration and resend-activation are refused |
|
|
119
|
-
| `AUTH_REGISTER_ROLES` | — (refused) | the role(s) a self-registered account gets when it is activated, comma-separated, e.g. `Viewer
|
|
119
|
+
| `AUTH_REGISTER_ROLES` | — (refused) | the role(s) a self-registered account gets when it is activated, comma-separated, e.g. `Viewer` — **any case** (`viewer` is Viewer; two roles differing only in case cannot be created). **No default, on purpose:** an account with no role has every role-mapped API hidden — its own profile included — so it can sign in and do nothing. Which role fits is each app's decision. Unset, a name that is not a generic (`mtId1 = '*'`) role, or a system role (Super Admin) → registration is refused |
|
|
120
120
|
| `AUTH_RESET_URL` | — (refused) | full address of your reset-password page, e.g. `http://localhost:19100/auth/reset-password`; `?token=…` is appended. Derived from `AUTH_ACTIVATION_BASE_URL` when only that is set. **Never taken from the request:** a link built from the `Host` header lets anyone have us mail a real user a reset link to their own site. Unset → forgot-password is refused |
|
|
121
121
|
| email (`EMAIL_PROVIDER` + its settings, below) | — | registration, resend-activation, invites and password reset all send a link. `boot()` checks mail at startup; when it is known not to work those routes refuse up front (`503`, `EMAIL_NOT_SET_UP`) rather than create an account whose link never goes out |
|
|
122
122
|
|
package/lib/userRoles.js
CHANGED
|
@@ -38,7 +38,7 @@ async function grantRoles(userId, roleIds, options) {
|
|
|
38
38
|
// quietly creating accounts that cannot use the app.
|
|
39
39
|
//
|
|
40
40
|
// Read at call time, like AUTH_ACTIVATION_URL, so the .env the app has
|
|
41
|
-
// loaded is the one used. System roles (Super Admin) are refused: a sign-up
|
|
41
|
+
// loaded is the one used. Names match in any case (viewer = Viewer). System roles (Super Admin) are refused: a sign-up
|
|
42
42
|
// form must never be a way to become one.
|
|
43
43
|
var REGISTER_ROLES_VAR = 'AUTH_REGISTER_ROLES';
|
|
44
44
|
|
|
@@ -58,9 +58,13 @@ async function registerRoleIds(knex) {
|
|
|
58
58
|
'account gets, comma-separated (for example Viewer). Registration is refused until it is.');
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
// Any case: "viewer" is the Viewer role. Two roles that differ only in case
|
|
62
|
+
// cannot exist — creating or renaming one is refused (adminRouter nameTaken).
|
|
61
63
|
var RoleM = knex ? Role.bindKnex(knex) : Role;
|
|
62
|
-
var
|
|
63
|
-
var
|
|
64
|
+
var lower = names.map(function(n) { return n.toLowerCase(); });
|
|
65
|
+
var roles = await RoleM.query().select('id', 'name', 'scope').where('mtId1', '*')
|
|
66
|
+
.whereRaw('lower(name) in (' + lower.map(function() { return '?'; }).join(', ') + ')', lower);
|
|
67
|
+
var missing = names.filter(function(n) { return !roles.some(function(r) { return r.name.toLowerCase() === n.toLowerCase(); }); });
|
|
64
68
|
if (missing.length) {
|
|
65
69
|
throw refusal('REGISTER_ROLES_UNKNOWN', REGISTER_ROLES_VAR + ' names ' +
|
|
66
70
|
(missing.length > 1 ? 'roles that do' : 'a role that does') + ' not exist: ' + missing.join(', ') + '.');
|