@faable/auth-sdk 2.9.12 → 2.9.14

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 CHANGED
@@ -17,12 +17,12 @@ Programmatically manage FaableAuth users, teams, connections and clients through
17
17
  > SDK itself has no Node-only dependencies and bundles for the browser. What
18
18
  > you must never ship to a browser or any untrusted runtime is a
19
19
  > **`client_secret`** or an **API key** — those grant management scopes over
20
- > the whole tenant. A user's own bearer token or the browser's session cookie
20
+ > the tenant. A user's own bearer token or the browser's session cookie
21
21
  > only grant what that user can do, and those are fine client-side.
22
22
 
23
23
  | Strategy | Credential | Grants | Where |
24
24
  | ----------------------- | --------------------------------- | ------------------------------------------------------------------ | --------------------------------------- |
25
- | `authClientCredentials` | `client_id` + **`client_secret`** | The management scopes of the client (full catalog unless narrowed) | **Server only** |
25
+ | `authClientCredentials` | `client_id` + **`client_secret`** | The client's Management API scopes (its allow-list; none by default) | **Server only** |
26
26
  | `authApikey` | **API key** (`fak_…`) | The management scopes of the key | **Server only** |
27
27
  | `authBearer` | A token the caller already holds | Whatever that token's scopes and subject allow | Anywhere the token itself may live |
28
28
  | `authCookie` | The browser's session cookie | The signed-in user's own session (`/me`, MFA, passkeys…) | Browser, same-origin with the auth host |
@@ -66,6 +66,16 @@ const api = FaableAuthApi.create({
66
66
  });
67
67
  ```
68
68
 
69
+ **Allow the client its Management API scopes first.** The token carries at most
70
+ the client's allow-list (`management_scopes`): with no `scope` in `auth`, the
71
+ whole list; with `scope`, the requested ones that are on it. A new client's list
72
+ is empty, so until you allow scopes (dashboard → your Auth tenant → Clients →
73
+ the client → OAuth → **Management API scopes**) every call fails with a
74
+ `FaableApiError` whose message names `management_scopes_empty` and says where to
75
+ fix it; asking only for scopes outside the list names
76
+ `management_scope_not_allowed`. See
77
+ [Calling the Faable Management API](https://faable.com/docs/auth/oauth-flows/client-credentials#management-api-scopes).
78
+
69
79
  By default the token is requested from `<domain>/oauth/token`. If your API host
70
80
  is **not** the auth server, override it with `auth.domain`:
71
81
 
@@ -3,13 +3,16 @@ import { FaableApiError } from "@faable/sdk-base";
3
3
  import { GeneratedFaableAuthApi } from "./api/generated-client.js";
4
4
  import { authClientCredentials } from "@faable/sdk-base";
5
5
  import { SDK_CLIENT } from "./version.js";
6
+ import { withManagementTokenErrors } from "./management_errors.js";
6
7
  // auth-sdk exists to drive the Faable management API, so a client_credentials
7
8
  // client should "just work" against it from `domain` alone. The management API
8
9
  // audience is `faable:management:<account_id>`, where `<account_id>` is this
9
10
  // host's tenant. We discover it from the public OIDC discovery document (which
10
11
  // resolves the account by host and exposes its id as `account`) lazily on the
11
- // first token request, and memoize it. Omitting `scope` then yields the full
12
- // management catalog server-side (Auth0 parity), so no scope wiring is needed.
12
+ // first token request, and memoize it. Omitting `scope` then yields the
13
+ // client's own Management API allow-list (`management_scopes`) server-side —
14
+ // not the whole catalog, and nothing at all while that list is empty; the two
15
+ // refusals get an actionable message (management_errors.ts).
13
16
  //
14
17
  // The memo is module-level, keyed by host. It used to be a closure created per
15
18
  // constructor, so it only ever helped an instance that outlived several token
@@ -86,6 +89,12 @@ export class FaableAuthApi extends GeneratedFaableAuthApi {
86
89
  baseURL,
87
90
  ...params,
88
91
  auth,
92
+ // Same strategy, with the Management API allow-list refusals of the
93
+ // token endpoint explained (management_errors.ts). Only for
94
+ // client_credentials: other strategies never call /oauth/token.
95
+ ...(usesClientCredentials && {
96
+ authStrategy: withManagementTokenErrors(params.authStrategy ?? authClientCredentials),
97
+ }),
89
98
  // Identify ourselves as a first-party client (`x-faable-client:
90
99
  // auth-sdk/<version>+<sha>`, surfaced as the `client`/`client_version`/
91
100
  // `client_sha` tags), and forward any consumer-supplied `name`/`instance`
@@ -7143,7 +7143,7 @@ export declare abstract class GeneratedFaableAuthApi extends FaableApi {
7143
7143
  *
7144
7144
  * Import users, with their password hashes
7145
7145
  *
7146
- * Creates up to 500 users per request, for migrations from another provider. Each row can carry a `password_hash` exported from that provider (bcrypt, scrypt, Firebase scrypt, PBKDF2, argon2): the user signs in with their existing password and the hash is upgraded to argon2id on that first login. Fast digests (MD5, SHA-1, SHA-2) and low costs are refused per row with `weak_password_hash`. Rows are matched by email, so the same file can be sent twice: existing users are `skipped` unless `update_existing`. A bad row never fails the batch: each row gets its own `status` and `error`. Imported users get none of the built-in new-user emails. The response never contains a hash, and neither does the audit log.
7146
+ * Creates up to 500 users per request, for migrations from another provider. Each row can carry a `password_hash` exported from that provider (bcrypt, scrypt, Firebase scrypt, PBKDF2, argon2, WordPress 6.8+ `$wp$2y$`): the user signs in with their existing password and the hash is upgraded to argon2id on that first login. Fast digests (MD5, SHA-1, SHA-2) and low costs are refused per row with `weak_password_hash`. Rows are matched by email, so the same file can be sent twice: existing users are `skipped` unless `update_existing`. A bad row never fails the batch: each row gets its own `status` and `error`. Imported users get none of the built-in new-user emails. The response never contains a hash, and neither does the audit log.
7147
7147
  *
7148
7148
  * @throws {FaableApiError} `validation_error` (400) — The body, query or path failed schema validation. `details.issues` lists each failing field.
7149
7149
  * @throws {FaableApiError} `unauthorized` (401) — The request carries no valid credentials.
@@ -2740,7 +2740,7 @@ export class GeneratedFaableAuthApi extends FaableApi {
2740
2740
  *
2741
2741
  * Import users, with their password hashes
2742
2742
  *
2743
- * Creates up to 500 users per request, for migrations from another provider. Each row can carry a `password_hash` exported from that provider (bcrypt, scrypt, Firebase scrypt, PBKDF2, argon2): the user signs in with their existing password and the hash is upgraded to argon2id on that first login. Fast digests (MD5, SHA-1, SHA-2) and low costs are refused per row with `weak_password_hash`. Rows are matched by email, so the same file can be sent twice: existing users are `skipped` unless `update_existing`. A bad row never fails the batch: each row gets its own `status` and `error`. Imported users get none of the built-in new-user emails. The response never contains a hash, and neither does the audit log.
2743
+ * Creates up to 500 users per request, for migrations from another provider. Each row can carry a `password_hash` exported from that provider (bcrypt, scrypt, Firebase scrypt, PBKDF2, argon2, WordPress 6.8+ `$wp$2y$`): the user signs in with their existing password and the hash is upgraded to argon2id on that first login. Fast digests (MD5, SHA-1, SHA-2) and low costs are refused per row with `weak_password_hash`. Rows are matched by email, so the same file can be sent twice: existing users are `skipped` unless `update_existing`. A bad row never fails the batch: each row gets its own `status` and `error`. Imported users get none of the built-in new-user emails. The response never contains a hash, and neither does the audit log.
2744
2744
  *
2745
2745
  * @throws {FaableApiError} `validation_error` (400) — The body, query or path failed schema validation. `details.issues` lists each failing field.
2746
2746
  * @throws {FaableApiError} `unauthorized` (401) — The request carries no valid credentials.
@@ -931,7 +931,7 @@ export interface paths {
931
931
  put?: never;
932
932
  /**
933
933
  * Import users, with their password hashes
934
- * @description Creates up to 500 users per request, for migrations from another provider. Each row can carry a `password_hash` exported from that provider (bcrypt, scrypt, Firebase scrypt, PBKDF2, argon2): the user signs in with their existing password and the hash is upgraded to argon2id on that first login. Fast digests (MD5, SHA-1, SHA-2) and low costs are refused per row with `weak_password_hash`. Rows are matched by email, so the same file can be sent twice: existing users are `skipped` unless `update_existing`. A bad row never fails the batch: each row gets its own `status` and `error`. Imported users get none of the built-in new-user emails. The response never contains a hash, and neither does the audit log.
934
+ * @description Creates up to 500 users per request, for migrations from another provider. Each row can carry a `password_hash` exported from that provider (bcrypt, scrypt, Firebase scrypt, PBKDF2, argon2, WordPress 6.8+ `$wp$2y$`): the user signs in with their existing password and the hash is upgraded to argon2id on that first login. Fast digests (MD5, SHA-1, SHA-2) and low costs are refused per row with `weak_password_hash`. Rows are matched by email, so the same file can be sent twice: existing users are `skipped` unless `update_existing`. A bad row never fails the batch: each row gets its own `status` and `error`. Imported users get none of the built-in new-user emails. The response never contains a hash, and neither does the audit log.
935
935
  */
936
936
  post: operations["user/import"];
937
937
  delete?: never;
@@ -17191,7 +17191,7 @@ export interface operations {
17191
17191
  };
17192
17192
  /** @description A password hash exported from another provider. Verified on the first login and upgraded to argon2id. Fast digests (MD5, SHA-1, SHA-2) and low costs are refused with `weak_password_hash`. */
17193
17193
  password_hash?: string | {
17194
- /** @description `bcrypt`, `argon2id`, `argon2i`, `argon2d`, `scrypt`, `pbkdf2-sha256`, `pbkdf2-sha512` or `firebase-scrypt`. */
17194
+ /** @description `bcrypt`, `argon2id`, `argon2i`, `argon2d`, `scrypt`, `pbkdf2-sha256`, `pbkdf2-sha512`, `firebase-scrypt` or `wordpress`. */
17195
17195
  algorithm: string;
17196
17196
  /** @description The hash, or its base64 digest when `salt` is given. */
17197
17197
  hash: string;
@@ -18831,7 +18831,7 @@ export interface operations {
18831
18831
  password?: string;
18832
18832
  /** @description A password hash exported from another provider. Verified on the first login and upgraded to argon2id. Fast digests (MD5, SHA-1, SHA-2) and low costs are refused with `weak_password_hash`. */
18833
18833
  password_hash?: string | {
18834
- /** @description `bcrypt`, `argon2id`, `argon2i`, `argon2d`, `scrypt`, `pbkdf2-sha256`, `pbkdf2-sha512` or `firebase-scrypt`. */
18834
+ /** @description `bcrypt`, `argon2id`, `argon2i`, `argon2d`, `scrypt`, `pbkdf2-sha256`, `pbkdf2-sha512`, `firebase-scrypt` or `wordpress`. */
18835
18835
  algorithm: string;
18836
18836
  /** @description The hash, or its base64 digest when `salt` is given. */
18837
18837
  hash: string;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./FaableAuthApi.js";
2
2
  export { SDK_CLIENT, commit, version } from "./version.js";
3
+ export { MANAGEMENT_SCOPES_DOCS } from "./management_errors.js";
3
4
  export * from "./api/generated-client.js";
4
5
  export * from "./api/api-types.js";
5
6
  export * from "./api/types.js";
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from "./FaableAuthApi.js";
2
2
  export { SDK_CLIENT, commit, version } from "./version.js";
3
+ // The Management API allow-list refusals of the token endpoint, explained.
4
+ export { MANAGEMENT_SCOPES_DOCS } from "./management_errors.js";
3
5
  export * from "./api/generated-client.js";
4
6
  export * from "./api/api-types.js";
5
7
  export * from "./api/types.js";
@@ -0,0 +1,17 @@
1
+ import { FaableApiError } from "@faable/sdk-base";
2
+ import type { AuthStrategyBuilder } from "@faable/sdk-base";
3
+ export declare const MANAGEMENT_SCOPES_DOCS = "https://faable.com/docs/auth/oauth-flows/client-credentials#management-api-scopes";
4
+ /**
5
+ * The same error with an actionable message when it is one of the two
6
+ * allow-list refusals of the token endpoint; `undefined` otherwise.
7
+ */
8
+ export declare const managementTokenError: (err: unknown, client_id?: string, scope?: string | string[]) => FaableApiError | undefined;
9
+ /**
10
+ * Wraps a client_credentials strategy so a refused Management API token
11
+ * surfaces as {@link managementTokenError}. Every other outcome — tokens,
12
+ * other errors, the 401 renewal — is the wrapped strategy's own.
13
+ */
14
+ export declare const withManagementTokenErrors: <TConfig extends {
15
+ client_id?: string | undefined;
16
+ scope?: string | string[] | undefined;
17
+ }>(builder: AuthStrategyBuilder<TConfig>) => AuthStrategyBuilder<TConfig>;
@@ -0,0 +1,68 @@
1
+ import { FaableApiError } from "@faable/sdk-base";
2
+ // The Management API token a client_credentials client obtains is bounded by
3
+ // the client's own allow-list (`Client.management_scopes`, auth ≥ the release
4
+ // that introduced it): a request with no `scope` — what this SDK sends by
5
+ // default — gets the whole list, and an EMPTY list is refused. The token
6
+ // endpoint answers with RFC 6749 errors, whose body has no `message`, so the
7
+ // sdk-base error would read "ERR_BAD_REQUEST (status=403, …)". These two
8
+ // codes get a sentence that says what to change and where. Nothing else is
9
+ // touched: the original response stays on the error (`error_code`, `status`).
10
+ export const MANAGEMENT_SCOPES_DOCS = "https://faable.com/docs/auth/oauth-flows/client-credentials#management-api-scopes";
11
+ const WHERE = "In the Faable dashboard open your Auth tenant → Clients → this client → OAuth → " +
12
+ "Management API scopes";
13
+ const explain = (code, client_id, scope) => {
14
+ const client = client_id ? `client ${client_id}` : "this client";
15
+ if (code === "management_scopes_empty") {
16
+ return (`FaableAuthApi: auth refused a Management API token to ${client} because ` +
17
+ "it is not allowed any Management API scopes (management_scopes_empty). " +
18
+ `${WHERE} and allow the scopes this backend uses (e.g. read:users), or send ` +
19
+ `\`management_scopes\` on POST /client/:id. See ${MANAGEMENT_SCOPES_DOCS}`);
20
+ }
21
+ if (code === "management_scope_not_allowed") {
22
+ return (`FaableAuthApi: none of the requested scopes${scope ? ` (${scope})` : ""} ` +
23
+ `is in the Management API scopes of ${client} (management_scope_not_allowed). ` +
24
+ `Request scopes that are on its list, or ${WHERE.charAt(0).toLowerCase()}${WHERE.slice(1)} ` +
25
+ `and add them. See ${MANAGEMENT_SCOPES_DOCS}`);
26
+ }
27
+ return undefined;
28
+ };
29
+ /**
30
+ * The same error with an actionable message when it is one of the two
31
+ * allow-list refusals of the token endpoint; `undefined` otherwise.
32
+ */
33
+ export const managementTokenError = (err, client_id, scope) => {
34
+ if (!(err instanceof FaableApiError))
35
+ return undefined;
36
+ const message = explain(err.error_code, client_id, Array.isArray(scope) ? scope.join(" ") : scope);
37
+ if (!message)
38
+ return undefined;
39
+ // The response is kept so `error_code`, `isErrorCode()` and `isStatus()`
40
+ // answer as before; only the sentence changes.
41
+ const explained = new FaableApiError(message, err.response);
42
+ // FaableApiError prefers the body's `message` over the one passed in; this
43
+ // sentence is the point, so it wins.
44
+ const status = err.response?.status;
45
+ explained.message = status ? `${message} (status=${status})` : message;
46
+ explained.code = err.code;
47
+ explained.cause = err;
48
+ return explained;
49
+ };
50
+ /**
51
+ * Wraps a client_credentials strategy so a refused Management API token
52
+ * surfaces as {@link managementTokenError}. Every other outcome — tokens,
53
+ * other errors, the 401 renewal — is the wrapped strategy's own.
54
+ */
55
+ export const withManagementTokenErrors = (builder) => (config, context) => {
56
+ const strategy = builder(config, context);
57
+ return {
58
+ ...strategy,
59
+ headers: async () => {
60
+ try {
61
+ return await strategy.headers();
62
+ }
63
+ catch (err) {
64
+ throw (managementTokenError(err, config?.client_id, config?.scope) ?? err);
65
+ }
66
+ },
67
+ };
68
+ };
package/dist/version.js CHANGED
@@ -9,13 +9,13 @@
9
9
  // login pages could not import the SDK at all. Same pattern as auth-js.
10
10
  //
11
11
  // The sentinels MUST stay byte-identical to the `from` values in `.releaserc`.
12
- export const version = "2.9.12";
12
+ export const version = "2.9.14";
13
13
  // Short git SHA of the released commit. The version dates a build; this names
14
14
  // the exact tree, so a canonical log line or an audit entry leads straight to
15
15
  // `git show <sha>`. Deliberately NOT hex: an unreleased build (dev, a local
16
16
  // link) cannot be mistaken for a real commit — auth only records values that
17
17
  // look like a SHA, and this one never will.
18
- export const commit = "959336c";
18
+ export const commit = "84917e9";
19
19
  // What this SDK writes in `x-faable-client`. Exported for a consumer that
20
20
  // builds a strategy on its own (outside `FaableAuthApi`) and still wants the
21
21
  // token request attributed — a bare `authClientCredentials` stamps only what
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/auth-sdk",
3
- "version": "2.9.12",
3
+ "version": "2.9.14",
4
4
  "author": "Marc Pomar <marc@faable.com>",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/spec/openapi.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "info": {
4
4
  "title": "@faablecloud/auth",
5
5
  "description": "Auth Platform made by Faable. Manage Users and Roles",
6
- "version": "2.99.2",
6
+ "version": "2.100.0",
7
7
  "license": {
8
8
  "name": "private",
9
9
  "url": "https://faable.com/docs/platform/privacy-policy"
@@ -32093,7 +32093,7 @@
32093
32093
  "tags": [
32094
32094
  "user"
32095
32095
  ],
32096
- "description": "Creates up to 500 users per request, for migrations from another provider. Each row can carry a `password_hash` exported from that provider (bcrypt, scrypt, Firebase scrypt, PBKDF2, argon2): the user signs in with their existing password and the hash is upgraded to argon2id on that first login. Fast digests (MD5, SHA-1, SHA-2) and low costs are refused per row with `weak_password_hash`. Rows are matched by email, so the same file can be sent twice: existing users are `skipped` unless `update_existing`. A bad row never fails the batch: each row gets its own `status` and `error`. Imported users get none of the built-in new-user emails. The response never contains a hash, and neither does the audit log.",
32096
+ "description": "Creates up to 500 users per request, for migrations from another provider. Each row can carry a `password_hash` exported from that provider (bcrypt, scrypt, Firebase scrypt, PBKDF2, argon2, WordPress 6.8+ `$wp$2y$`): the user signs in with their existing password and the hash is upgraded to argon2id on that first login. Fast digests (MD5, SHA-1, SHA-2) and low costs are refused per row with `weak_password_hash`. Rows are matched by email, so the same file can be sent twice: existing users are `skipped` unless `update_existing`. A bad row never fails the batch: each row gets its own `status` and `error`. Imported users get none of the built-in new-user emails. The response never contains a hash, and neither does the audit log.",
32097
32097
  "requestBody": {
32098
32098
  "required": true,
32099
32099
  "content": {
@@ -32160,7 +32160,7 @@
32160
32160
  "type": "string",
32161
32161
  "minLength": 1,
32162
32162
  "maxLength": 1024,
32163
- "description": "A self-describing hash: bcrypt (`$2a$`/`$2b$`/`$2y$`), argon2 PHC (`$argon2id$…`), scrypt PHC (`$scrypt$ln=…`), PBKDF2 (`$pbkdf2-sha256$i=…` or Django `pbkdf2_sha256$…`)."
32163
+ "description": "A self-describing hash: bcrypt (`$2a$`/`$2b$`/`$2y$`), argon2 PHC (`$argon2id$…`), scrypt PHC (`$scrypt$ln=…`), PBKDF2 (`$pbkdf2-sha256$i=…` or Django `pbkdf2_sha256$…`), WordPress 6.8+ (`$wp$2y$…`, as stored in `wp_users.user_pass`)."
32164
32164
  },
32165
32165
  {
32166
32166
  "type": "object",
@@ -32171,7 +32171,7 @@
32171
32171
  "properties": {
32172
32172
  "algorithm": {
32173
32173
  "type": "string",
32174
- "description": "`bcrypt`, `argon2id`, `argon2i`, `argon2d`, `scrypt`, `pbkdf2-sha256`, `pbkdf2-sha512` or `firebase-scrypt`."
32174
+ "description": "`bcrypt`, `argon2id`, `argon2i`, `argon2d`, `scrypt`, `pbkdf2-sha256`, `pbkdf2-sha512`, `firebase-scrypt` or `wordpress`."
32175
32175
  },
32176
32176
  "hash": {
32177
32177
  "type": "string",
@@ -35695,7 +35695,7 @@
35695
35695
  "type": "string",
35696
35696
  "minLength": 1,
35697
35697
  "maxLength": 1024,
35698
- "description": "A self-describing hash: bcrypt (`$2a$`/`$2b$`/`$2y$`), argon2 PHC (`$argon2id$…`), scrypt PHC (`$scrypt$ln=…`), PBKDF2 (`$pbkdf2-sha256$i=…` or Django `pbkdf2_sha256$…`)."
35698
+ "description": "A self-describing hash: bcrypt (`$2a$`/`$2b$`/`$2y$`), argon2 PHC (`$argon2id$…`), scrypt PHC (`$scrypt$ln=…`), PBKDF2 (`$pbkdf2-sha256$i=…` or Django `pbkdf2_sha256$…`), WordPress 6.8+ (`$wp$2y$…`, as stored in `wp_users.user_pass`)."
35699
35699
  },
35700
35700
  {
35701
35701
  "type": "object",
@@ -35706,7 +35706,7 @@
35706
35706
  "properties": {
35707
35707
  "algorithm": {
35708
35708
  "type": "string",
35709
- "description": "`bcrypt`, `argon2id`, `argon2i`, `argon2d`, `scrypt`, `pbkdf2-sha256`, `pbkdf2-sha512` or `firebase-scrypt`."
35709
+ "description": "`bcrypt`, `argon2id`, `argon2i`, `argon2d`, `scrypt`, `pbkdf2-sha256`, `pbkdf2-sha512`, `firebase-scrypt` or `wordpress`."
35710
35710
  },
35711
35711
  "hash": {
35712
35712
  "type": "string",