@friggframework/core 2.0.0--canary.688.87a9bf3.0 → 2.0.0--canary.690.d043f23.0
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/CLAUDE.md +28 -0
- package/README.md +105 -0
- package/application/commands/entity-commands.js +60 -18
- package/application/commands/integration-commands.js +20 -10
- package/application/commands/scheduler-commands.js +11 -7
- package/application/commands/user-commands.js +17 -5
- package/application/index.js +6 -2
- package/core/Worker.js +31 -7
- package/core/create-handler.js +9 -0
- package/credential/repositories/credential-repository-documentdb.js +34 -0
- package/credential/repositories/credential-repository-interface.js +15 -0
- package/credential/repositories/credential-repository-mongo.js +23 -0
- package/credential/repositories/credential-repository-postgres.js +28 -0
- package/credential/use-cases/credential-operations-for-user.js +202 -0
- package/credential/use-cases/reauthorize-credential-for-user.js +73 -0
- package/database/config.js +48 -24
- package/database/documentdb-utils.js +2 -0
- package/database/encryption/encryption-schema-registry.js +93 -12
- package/database/organization-where.js +18 -0
- package/database/prisma.js +4 -2
- package/database/unique-violation.js +25 -0
- package/errors/index.js +0 -4
- package/extensions/bootstrap-runner.js +43 -0
- package/extensions/extension-loader.js +167 -0
- package/extensions/index.js +41 -0
- package/extensions/initialize-app.js +123 -0
- package/extensions/route-mounter.js +103 -0
- package/extensions/schema-composer.js +188 -0
- package/generated/prisma-mongodb/edge.js +43 -4
- package/generated/prisma-mongodb/index-browser.js +40 -1
- package/generated/prisma-mongodb/index.d.ts +4761 -133
- package/generated/prisma-mongodb/index.js +43 -4
- package/generated/prisma-mongodb/package.json +1 -1
- package/generated/prisma-mongodb/schema.prisma +92 -0
- package/generated/prisma-mongodb/wasm.js +43 -4
- package/generated/prisma-postgresql/edge.js +43 -4
- package/generated/prisma-postgresql/index-browser.js +40 -1
- package/generated/prisma-postgresql/index.d.ts +4961 -28
- package/generated/prisma-postgresql/index.js +43 -4
- package/generated/prisma-postgresql/package.json +1 -1
- package/generated/prisma-postgresql/schema.prisma +87 -0
- package/generated/prisma-postgresql/wasm.js +43 -4
- package/handlers/WEBHOOKS.md +0 -29
- package/handlers/app-definition-loader.js +118 -19
- package/handlers/app-handler-helpers.js +25 -3
- package/handlers/backend-utils.js +31 -25
- package/handlers/middleware/admin-auth.js +14 -1
- package/handlers/routers/auth.js +46 -10
- package/handlers/routers/health.js +11 -4
- package/handlers/routers/integration-defined-routers.js +144 -92
- package/handlers/routers/integration-webhook-routers.js +102 -64
- package/handlers/workers/integration-defined-workers.js +5 -2
- package/index.js +63 -3
- package/infrastructure/scheduler/index.js +19 -6
- package/infrastructure/scheduler/netlify-scheduler-adapter.js +216 -0
- package/infrastructure/scheduler/scheduled-job-repository.js +118 -0
- package/infrastructure/scheduler/scheduler-service-factory.js +55 -7
- package/integrations/index.js +1 -0
- package/integrations/integration-base.js +0 -29
- package/integrations/integration-router.js +131 -96
- package/integrations/repositories/integration-mapping-repository-documentdb.js +0 -50
- package/integrations/repositories/integration-mapping-repository-interface.js +0 -15
- package/integrations/repositories/integration-mapping-repository-mongo.js +0 -29
- package/integrations/repositories/integration-mapping-repository-postgres.js +0 -30
- package/integrations/repositories/integration-mapping-repository.js +0 -29
- package/integrations/repositories/integration-not-found.js +14 -0
- package/integrations/repositories/integration-repository-documentdb.js +35 -3
- package/integrations/repositories/integration-repository-interface.js +17 -1
- package/integrations/repositories/integration-repository-mongo.js +60 -77
- package/integrations/repositories/integration-repository-postgres.js +62 -76
- package/integrations/repositories/process-repository-mongo.js +1 -1
- package/integrations/tests/doubles/test-integration-repository.js +12 -1
- package/integrations/use-cases/create-integration.js +55 -20
- package/integrations/use-cases/get-integrations-for-user.js +80 -40
- package/integrations/use-cases/index.js +5 -1
- package/integrations/use-cases/integration-operations-for-user.js +256 -0
- package/integrations/use-cases/resolve-integration-ownership.js +177 -0
- package/integrations/utils/map-integration-dto.js +43 -14
- package/management-api/create-management-api-router.js +49 -0
- package/management-api/error-response.js +116 -0
- package/management-api/management-api-config.js +151 -0
- package/management-api/meta-router.js +57 -0
- package/management-api/openapi/build-openapi.js +144 -0
- package/management-api/openapi/components.js +414 -0
- package/management-api/openapi/v1-operations.js +83 -0
- package/management-api/openapi/v2-operations.js +264 -0
- package/management-api/route-registry.js +294 -0
- package/management-api/test-support/http-client.js +39 -0
- package/management-api/use-cases/get-management-api-meta.js +57 -0
- package/management-api/v1-deprecation.js +120 -0
- package/management-api/v2/create-v2-router.js +85 -0
- package/management-api/v2/dependencies.js +281 -0
- package/management-api/v2/dto.js +143 -0
- package/management-api/v2/handlers/authorization.js +94 -0
- package/management-api/v2/handlers/credentials.js +33 -0
- package/management-api/v2/handlers/entities.js +77 -0
- package/management-api/v2/handlers/integrations.js +128 -0
- package/management-api/v2/handlers/proxy.js +34 -0
- package/management-api/v2/request.js +85 -0
- package/management-api/v2/test-support/fake-dependencies.js +103 -0
- package/modules/domain/authorization-session.js +144 -0
- package/modules/entity-scope.js +15 -0
- package/modules/entity-type-registry.js +311 -0
- package/modules/index.js +14 -0
- package/modules/module-factory.js +12 -0
- package/modules/module.js +53 -2
- package/modules/proxy/proxy-bases.js +169 -0
- package/modules/proxy/proxy-errors.js +31 -0
- package/modules/proxy/proxy-path.js +183 -0
- package/modules/proxy/proxy-policy.js +265 -0
- package/modules/repositories/authorization-session-repository-documentdb.js +112 -0
- package/modules/repositories/authorization-session-repository-factory.js +31 -0
- package/modules/repositories/authorization-session-repository-interface.js +47 -0
- package/modules/repositories/authorization-session-repository-prisma.js +87 -0
- package/modules/repositories/entity-not-found.js +18 -0
- package/modules/repositories/module-repository-documentdb.js +51 -6
- package/modules/repositories/module-repository-interface.js +19 -2
- package/modules/repositories/module-repository-mongo.js +67 -74
- package/modules/repositories/module-repository-postgres.js +66 -74
- package/modules/repositories/module-repository.js +2 -1
- package/modules/requester/proxy-request.js +245 -0
- package/modules/requester/requester.js +27 -2
- package/modules/scope-config.js +192 -0
- package/modules/scope-policy.js +112 -0
- package/modules/scope-resolution.js +288 -0
- package/modules/scope-visibility.js +247 -0
- package/modules/tests/doubles/in-memory-authorization-session-repository.js +45 -0
- package/modules/tests/doubles/ownership-matching.js +18 -0
- package/modules/use-cases/authorize-entity-for-user.js +61 -0
- package/modules/use-cases/create-entity-from-credential.js +113 -0
- package/modules/use-cases/entity-operations-for-user.js +162 -0
- package/modules/use-cases/entity-types.js +139 -0
- package/modules/use-cases/execute-entity-proxy-request.js +331 -0
- package/modules/use-cases/get-authorization-requirements.js +100 -0
- package/modules/use-cases/get-entities-for-user.js +26 -13
- package/modules/use-cases/get-entity-module-for-user.js +113 -0
- package/modules/use-cases/get-entity-options-by-id.js +10 -4
- package/modules/use-cases/get-entity-options-by-type.js +1 -1
- package/modules/use-cases/get-module-instance-from-type.js +1 -1
- package/modules/use-cases/get-module.js +10 -4
- package/modules/use-cases/manage-access.js +21 -0
- package/modules/use-cases/multi-step-authorization.js +329 -0
- package/modules/use-cases/process-authorization-callback.js +53 -19
- package/modules/use-cases/refresh-entity-options.js +10 -4
- package/modules/use-cases/test-module-auth.js +10 -4
- package/modules/utils/map-module-dto.js +3 -5
- package/package.json +6 -5
- package/prisma-mongodb/schema.prisma +92 -0
- package/prisma-postgresql/migrations/20261003000000_add_authorization_session/migration.sql +28 -0
- package/prisma-postgresql/migrations/20261015000000_add_organization_membership/migration.sql +26 -0
- package/prisma-postgresql/migrations/20261016000000_add_entity_integration_organization/migration.sql +25 -0
- package/prisma-postgresql/migrations/20261017000000_add_scheduled_job/migration.sql +28 -0
- package/prisma-postgresql/schema.prisma +87 -0
- package/providers/index.js +13 -0
- package/providers/resolve-provider.js +93 -0
- package/queues/index.js +25 -0
- package/queues/providers/index.js +11 -0
- package/queues/providers/netlify-background-provider.js +150 -0
- package/queues/providers/qstash-queue-provider.js +199 -0
- package/queues/providers/sqs-queue-provider.js +70 -0
- package/queues/queue-client-interface.js +55 -0
- package/queues/queue-message-auth.js +187 -0
- package/queues/queue-provider-factory.js +101 -0
- package/queues/queue-provider.js +65 -0
- package/queues/sqs-queue-client.js +81 -0
- package/types/index.d.ts +2 -0
- package/types/modules/index.d.ts +214 -0
- package/types/user/index.d.ts +134 -0
- package/user/adopter-jwt-config.js +177 -0
- package/user/adopter-jwt-errors.js +59 -0
- package/user/adopter-token-verifier.js +122 -0
- package/user/app-user-helpers.js +97 -0
- package/user/create-user-authentication.js +64 -0
- package/user/membership.js +51 -0
- package/user/repositories/organization-membership-record.js +19 -0
- package/user/repositories/organization-membership-repository-documentdb.js +106 -0
- package/user/repositories/organization-membership-repository-factory.js +42 -0
- package/user/repositories/organization-membership-repository-interface.js +57 -0
- package/user/repositories/organization-membership-repository-mongo.js +13 -0
- package/user/repositories/organization-membership-repository-postgres.js +29 -0
- package/user/repositories/organization-membership-repository-prisma.js +81 -0
- package/user/repositories/user-repository-documentdb.js +27 -2
- package/user/repositories/user-repository-interface.js +18 -0
- package/user/repositories/user-repository-mongo.js +24 -0
- package/user/repositories/user-repository-postgres.js +18 -0
- package/user/tests/doubles/adopter-jwt-fixtures.js +220 -0
- package/user/use-cases/authenticate-user.js +7 -1
- package/user/use-cases/ensure-organization-membership.js +92 -0
- package/user/use-cases/find-individual-users-by-organization.js +54 -0
- package/user/use-cases/get-user-from-adopter-jwt.js +95 -124
- package/user/use-cases/get-user-from-x-frigg-headers.js +83 -80
- package/user/user.js +64 -1
- package/errors/mapping-already-exists-error.js +0 -14
- package/modules/utils/to-credential-id.js +0 -14
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQS Queue Client (Adapter)
|
|
3
|
+
*
|
|
4
|
+
* AWS SQS implementation of QueueClientInterface, used by Worker.
|
|
5
|
+
*
|
|
6
|
+
* In friggframework/frigg#545 this adapter moved to
|
|
7
|
+
* @friggframework/provider-aws and Worker required it to be injected. In
|
|
8
|
+
* this stack the AWS SDK stays a core dependency, so the adapter lives here,
|
|
9
|
+
* Worker defaults to it, and provider-aws re-exports it. The SDK is
|
|
10
|
+
* required on first use, not at module load.
|
|
11
|
+
*/
|
|
12
|
+
const { QueueClientInterface } = require('./queue-client-interface');
|
|
13
|
+
|
|
14
|
+
let sqsModule = null;
|
|
15
|
+
function getSqsModule() {
|
|
16
|
+
if (!sqsModule) {
|
|
17
|
+
sqsModule = require('@aws-sdk/client-sqs');
|
|
18
|
+
}
|
|
19
|
+
return sqsModule;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Client config #545's adapter used: IS_OFFLINE credentials, AWS_REGION and
|
|
24
|
+
* AWS_ENDPOINT.
|
|
25
|
+
*/
|
|
26
|
+
function defaultSqsClientConfig() {
|
|
27
|
+
const config = {};
|
|
28
|
+
if (process.env.IS_OFFLINE) {
|
|
29
|
+
config.credentials = {
|
|
30
|
+
accessKeyId: 'test-aws-key',
|
|
31
|
+
secretAccessKey: 'test-aws-secret',
|
|
32
|
+
};
|
|
33
|
+
config.region = 'us-east-1';
|
|
34
|
+
}
|
|
35
|
+
if (!config.region && process.env.AWS_REGION) {
|
|
36
|
+
config.region = process.env.AWS_REGION;
|
|
37
|
+
}
|
|
38
|
+
if (process.env.AWS_ENDPOINT) {
|
|
39
|
+
config.endpoint = process.env.AWS_ENDPOINT;
|
|
40
|
+
}
|
|
41
|
+
return config;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class SqsQueueClient extends QueueClientInterface {
|
|
45
|
+
/**
|
|
46
|
+
* @param {Object} [options]
|
|
47
|
+
* @param {Object} [options.clientConfig] - SQSClient config; defaults to
|
|
48
|
+
* defaultSqsClientConfig().
|
|
49
|
+
*/
|
|
50
|
+
constructor({ clientConfig } = {}) {
|
|
51
|
+
super();
|
|
52
|
+
this._clientConfig = clientConfig;
|
|
53
|
+
this._sqs = null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
_client() {
|
|
57
|
+
if (!this._sqs) {
|
|
58
|
+
const { SQSClient } = getSqsModule();
|
|
59
|
+
this._sqs = new SQSClient(this._clientConfig || defaultSqsClientConfig());
|
|
60
|
+
}
|
|
61
|
+
return this._sqs;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async sendMessage(params) {
|
|
65
|
+
const { SendMessageCommand } = getSqsModule();
|
|
66
|
+
return this._client().send(new SendMessageCommand(params));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async sendMessageBatch(params) {
|
|
70
|
+
const { SendMessageBatchCommand } = getSqsModule();
|
|
71
|
+
return this._client().send(new SendMessageBatchCommand(params));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async getQueueUrl(params) {
|
|
75
|
+
const { GetQueueUrlCommand } = getSqsModule();
|
|
76
|
+
const data = await this._client().send(new GetQueueUrlCommand(params));
|
|
77
|
+
return data.QueueUrl;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = { SqsQueueClient, defaultSqsClientConfig };
|
package/types/index.d.ts
CHANGED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
declare module "@friggframework/core" {
|
|
2
|
+
/** Where an entity type comes from: the app's `entities` map or an integration binding it. */
|
|
3
|
+
export type EntityTypeSource =
|
|
4
|
+
| { kind: "app" }
|
|
5
|
+
| { kind: "integration"; name: string };
|
|
6
|
+
|
|
7
|
+
export type EntityScope = "individual" | "organization" | "global";
|
|
8
|
+
|
|
9
|
+
/** App-level settings carried from the `entities` entry; empty for an inferred-only type. */
|
|
10
|
+
export interface EntityTypeSettings {
|
|
11
|
+
scope?: EntityScope | { default?: EntityScope; allow?: EntityScope[] };
|
|
12
|
+
proxy?: Record<string, unknown>;
|
|
13
|
+
display?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface EntityTypeEntry {
|
|
17
|
+
/** The API module definition. */
|
|
18
|
+
definition: { moduleName?: string; proxy?: ModuleProxyConfig; [key: string]: any };
|
|
19
|
+
/** Frozen. `{ kind: 'app' }` first when registered, then each binding integration. */
|
|
20
|
+
sources: readonly EntityTypeSource[];
|
|
21
|
+
/** Frozen. */
|
|
22
|
+
settings: Readonly<EntityTypeSettings>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Entity type name (the definition's moduleName) to its entry. */
|
|
26
|
+
export type EntityTypeRegistry = Map<string, EntityTypeEntry>;
|
|
27
|
+
|
|
28
|
+
/** One `appDefinition.entities` entry. The key must equal the definition's moduleName (and getName() when defined). */
|
|
29
|
+
export interface EntityRegistration extends EntityTypeSettings {
|
|
30
|
+
definition: any;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AppDefinitionEntities {
|
|
34
|
+
/** false turns inference off: every module an integration binds must be registered. Default true. */
|
|
35
|
+
$infer?: boolean;
|
|
36
|
+
[entityType: string]: EntityRegistration | boolean | undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* One level's setting: a scope, or a default plus the scopes a request may
|
|
41
|
+
* choose from (ADR-056 §3.1). `global` is never chosen by a tenant request.
|
|
42
|
+
*/
|
|
43
|
+
export type ScopeSetting =
|
|
44
|
+
| EntityScope
|
|
45
|
+
| { default?: EntityScope; allow?: EntityScope[] };
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* `appDefinition.ownership` (ADR-056 §3, §3.6). Resolution order for a new
|
|
49
|
+
* connection: request, binding, integration, entity type (`entities[name].scope`),
|
|
50
|
+
* this `scope`, then `organization` for an organization-primary app and
|
|
51
|
+
* `individual` otherwise.
|
|
52
|
+
*/
|
|
53
|
+
export interface AppOwnership {
|
|
54
|
+
scope?: ScopeSetting;
|
|
55
|
+
/**
|
|
56
|
+
* `'organization'` (default): an individual entity belongs to the organization
|
|
57
|
+
* it was connected in. `'all'`: one connection per person across every
|
|
58
|
+
* organization, stored with no `organizationId`.
|
|
59
|
+
*/
|
|
60
|
+
individualAcross?: "organization" | "all";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** `Definition.ownership` on an integration (ADR-056 §3.1, §3.3). */
|
|
64
|
+
export interface IntegrationOwnership {
|
|
65
|
+
/** Scope every binding of this integration accepts unless it sets its own. */
|
|
66
|
+
scope?: ScopeSetting;
|
|
67
|
+
/** `'derive'` (default): organization when every entity it uses is organization-scoped. */
|
|
68
|
+
owner?: "derive" | "individual" | "organization";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** One operation a module or the app lets the entity proxy forward (ADR-052). */
|
|
72
|
+
export interface ProxyAllowRule {
|
|
73
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "*";
|
|
74
|
+
/** Relative to the module's base URL. `:param` is one segment; a trailing `/**` is a subtree. */
|
|
75
|
+
path: string;
|
|
76
|
+
/** Which of the module's named base URLs the rule applies to. Default `"default"`. Must be declared by the module (checked at load). */
|
|
77
|
+
base?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A module definition's `proxy` setting (ADR-052). Declare `baseUrl` (one host,
|
|
82
|
+
* meaning `{ default: baseUrl }`) or `baseUrls` (several), never both.
|
|
83
|
+
* `baseUrls` values are absolute https URLs with no credentials, query or
|
|
84
|
+
* fragment (strings only, unlike `baseUrl`); names match `^[a-z][a-z0-9-]*$`.
|
|
85
|
+
* A caller picks a base by name in the proxy request's `base`.
|
|
86
|
+
*/
|
|
87
|
+
export interface ModuleProxyConfig {
|
|
88
|
+
baseUrl?: string | ((api: any) => string);
|
|
89
|
+
baseUrls?: Record<string, string>;
|
|
90
|
+
allow?: ProxyAllowRule[];
|
|
91
|
+
headers?: string[];
|
|
92
|
+
binary?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** `appDefinition.managementApi.proxy`: the entity proxy, POST /api/v2/entities/:id/proxy (ADR-052). */
|
|
96
|
+
export interface ManagementApiProxyConfig {
|
|
97
|
+
/** Mount the route. Default false. */
|
|
98
|
+
enable?: boolean;
|
|
99
|
+
/** Upstream timeout in ms; can only be lowered from 25000. */
|
|
100
|
+
timeoutMs?: number;
|
|
101
|
+
/** Largest request body in bytes; default 1 MiB, at most 10 MiB. */
|
|
102
|
+
maxRequestBytes?: number;
|
|
103
|
+
/** Largest response body in bytes; can only be lowered from 5 MiB. */
|
|
104
|
+
maxResponseBytes?: number;
|
|
105
|
+
/**
|
|
106
|
+
* Entity scopes the proxy accepts (ADR-056 §3.5). Default `['individual']`.
|
|
107
|
+
* Add `'organization'` to let a member with use access proxy through the
|
|
108
|
+
* organization's shared credential. `global` is never accepted. An unknown,
|
|
109
|
+
* empty or repeated value throws ManagementApiConfigError at load.
|
|
110
|
+
*/
|
|
111
|
+
scopes?: Array<Exclude<EntityScope, "global">>;
|
|
112
|
+
/** Per-module allow-list override; `'module'` uses the module's own list. */
|
|
113
|
+
modules?: Record<string, { allow: "module" | ProxyAllowRule[] }>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** `appDefinition.managementApi` (ADR-052, ADR-053). */
|
|
117
|
+
export interface ManagementApiConfig {
|
|
118
|
+
/** Serve the deprecated v1 routes. Default true. */
|
|
119
|
+
v1?: boolean;
|
|
120
|
+
proxy?: ManagementApiProxyConfig;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface AppDefinition {
|
|
124
|
+
integrations: any[];
|
|
125
|
+
/** App-level entity type registry (ADR-059). */
|
|
126
|
+
entities?: AppDefinitionEntities;
|
|
127
|
+
/** Who owns what a person connects (ADR-056). */
|
|
128
|
+
ownership?: AppOwnership;
|
|
129
|
+
/** Management API versions and the entity proxy (ADR-052, ADR-053, ADR-056 §3.5). */
|
|
130
|
+
managementApi?: ManagementApiConfig;
|
|
131
|
+
[key: string]: unknown;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Whose a record is and what the caller may do with it (ADR-056 §3.4). */
|
|
135
|
+
export interface RecordTenancy {
|
|
136
|
+
scope: Exclude<EntityScope, "global">;
|
|
137
|
+
owner: { type: Exclude<EntityScope, "global">; id: string };
|
|
138
|
+
/** Null for an individual entity connected outside an organization, or under `individualAcross: 'all'`. */
|
|
139
|
+
organizationId: string | null;
|
|
140
|
+
/** `manage`: create, reauthorize, delete. `use`: bind it, proxy through it. `view`: metadata only. */
|
|
141
|
+
access: "manage" | "use" | "view";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Which scope a connection gets, and from which level of the order (ADR-056 §3.1). */
|
|
145
|
+
export interface ResolvedScope {
|
|
146
|
+
scope: EntityScope;
|
|
147
|
+
/** Where `scope` came from. `request` when the request chose within the allowed list. */
|
|
148
|
+
source: "request" | "binding" | "integration" | "entityType" | "app" | "default";
|
|
149
|
+
/** The level that decided what a request may choose from. */
|
|
150
|
+
decidedBy: "binding" | "integration" | "entityType" | "app" | "default";
|
|
151
|
+
allow: EntityScope[];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* First match wins, each level overriding the ones below it. A request may
|
|
156
|
+
* choose only from the deciding level's `allow`; `global` never comes from a
|
|
157
|
+
* tenant request. Throws a Boom 400/403 for a request scope that is not allowed.
|
|
158
|
+
*/
|
|
159
|
+
export function resolveScope(levels: {
|
|
160
|
+
request?: EntityScope;
|
|
161
|
+
binding?: ScopeSetting;
|
|
162
|
+
integration?: ScopeSetting;
|
|
163
|
+
entityType?: ScopeSetting;
|
|
164
|
+
app?: ScopeSetting;
|
|
165
|
+
primary?: "individual" | "organization";
|
|
166
|
+
}): ResolvedScope;
|
|
167
|
+
|
|
168
|
+
/** Every binding of every integration with its resolved scope (for tooling that wants to show the chain). */
|
|
169
|
+
export function listBindingScopes(
|
|
170
|
+
appDefinition: Pick<AppDefinition, "integrations" | "ownership">,
|
|
171
|
+
entityTypeRegistry: EntityTypeRegistry,
|
|
172
|
+
primary?: "individual" | "organization"
|
|
173
|
+
): Array<{
|
|
174
|
+
integration: string;
|
|
175
|
+
binding: string;
|
|
176
|
+
moduleName: string | null;
|
|
177
|
+
scope: EntityScope;
|
|
178
|
+
source: ResolvedScope["source"];
|
|
179
|
+
owner: "derive" | "individual" | "organization";
|
|
180
|
+
}>;
|
|
181
|
+
|
|
182
|
+
/** Invalid ownership or scope setting, thrown at app-definition load. `code` is always `OWNERSHIP_CONFIG_INVALID`. */
|
|
183
|
+
export class OwnershipConfigError extends Error {
|
|
184
|
+
code: "OWNERSHIP_CONFIG_INVALID";
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Builds the registry from `entities` plus the modules integrations bind.
|
|
189
|
+
* Throws EntityRegistryError on an invalid registry.
|
|
190
|
+
*/
|
|
191
|
+
export function getEntityTypeRegistry(
|
|
192
|
+
appDefinition?: Pick<AppDefinition, "entities" | "integrations">
|
|
193
|
+
): EntityTypeRegistry;
|
|
194
|
+
|
|
195
|
+
/** Invalid `managementApi` setting (today: `proxy.scopes`), thrown at app-definition load. */
|
|
196
|
+
export class ManagementApiConfigError extends Error {
|
|
197
|
+
code: "MANAGEMENT_API_CONFIG_INVALID";
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @deprecated ADR-059. Use `getEntityTypeRegistry(appDefinition)` and read
|
|
202
|
+
* each entry's `definition`. Returns the registry's definitions for these
|
|
203
|
+
* integrations (plus registry-only types when `entities` is passed).
|
|
204
|
+
*/
|
|
205
|
+
export function getModulesDefinitionFromIntegrationClasses(
|
|
206
|
+
integrationClasses: any[],
|
|
207
|
+
entities?: AppDefinitionEntities
|
|
208
|
+
): any[];
|
|
209
|
+
|
|
210
|
+
/** Invalid `entities` registry. `code` is always `ENTITY_REGISTRY_INVALID`. */
|
|
211
|
+
export class EntityRegistryError extends Error {
|
|
212
|
+
code: "ENTITY_REGISTRY_INVALID";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
declare module "@friggframework/core/user" {
|
|
2
|
+
export type AdopterJwtAlgorithm =
|
|
3
|
+
| "ES256"
|
|
4
|
+
| "ES384"
|
|
5
|
+
| "RS256"
|
|
6
|
+
| "RS384"
|
|
7
|
+
| "RS512"
|
|
8
|
+
| "HS256"
|
|
9
|
+
| "HS384"
|
|
10
|
+
| "HS512";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Verification of tokens issued by the adopter's identity system
|
|
14
|
+
* (`authModes.adopterJwt`, ADR-056 §2). Set exactly one of `jwksUri` or `secret`.
|
|
15
|
+
*/
|
|
16
|
+
export interface AdopterJwtConfig {
|
|
17
|
+
/** https URL of the issuer's JWKS (http only for localhost, 127.0.0.0/8, ::1). */
|
|
18
|
+
jwksUri?: string;
|
|
19
|
+
/** Shared HMAC secret for HS* tokens. */
|
|
20
|
+
secret?: string;
|
|
21
|
+
/** Required `iss`. With `jwksUri`, a startup warning is logged when unset. */
|
|
22
|
+
issuer?: string;
|
|
23
|
+
/** Accepted `aud`. Required with `jwksUri`. */
|
|
24
|
+
audience?: string | string[];
|
|
25
|
+
/** Allow-list. Default ES256 and RS256 with `jwksUri`, HS256 with `secret`. */
|
|
26
|
+
algorithms?: AdopterJwtAlgorithm[];
|
|
27
|
+
/** @deprecated Use `algorithms`. Setting both is an error. */
|
|
28
|
+
algorithm?: AdopterJwtAlgorithm;
|
|
29
|
+
/** Skew allowed on `exp` and `nbf`. Default 30. */
|
|
30
|
+
clockToleranceSec?: number;
|
|
31
|
+
/** Default `sub`. */
|
|
32
|
+
userIdClaim?: string;
|
|
33
|
+
/** Default `org_id`. */
|
|
34
|
+
orgIdClaim?: string;
|
|
35
|
+
/** Default `org_role`. Exposed as `User#getOrgRole()`; stored on a new membership. */
|
|
36
|
+
roleClaim?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface UserAuthModes {
|
|
40
|
+
friggToken?: boolean;
|
|
41
|
+
sharedSecret?: boolean;
|
|
42
|
+
adopterJwt?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The `user` block of the app definition. */
|
|
46
|
+
export interface UserConfig {
|
|
47
|
+
usePassword?: boolean;
|
|
48
|
+
primary?: "individual" | "organization";
|
|
49
|
+
individualUserRequired?: boolean;
|
|
50
|
+
organizationUserRequired?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* With `x-frigg` headers, refuse (400) to make a person a member of an
|
|
53
|
+
* organization that already existed: anyone not already a member, a
|
|
54
|
+
* brand-new `appUserId` included, is rejected. Naming an organization the
|
|
55
|
+
* request itself creates is still allowed. Default false (a non-member is
|
|
56
|
+
* added).
|
|
57
|
+
*/
|
|
58
|
+
strictMembership?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Alias of `strictMembership`, with the same new meaning (it
|
|
61
|
+
* used to reject a mismatched individual/organization pair). Logs a warning
|
|
62
|
+
* at startup. `strictMembership` wins when both are set.
|
|
63
|
+
*/
|
|
64
|
+
strictUserValidation?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Roles that may manage organization-level things (ADR-056 §3). Default
|
|
67
|
+
* `['ADMIN']`. The role is the adopter token's role claim, else the stored
|
|
68
|
+
* membership `orgRole`, else `MEMBER` (never admin). A shared-secret
|
|
69
|
+
* (`x-frigg` header) caller needs no role, nor does a Frigg bearer token
|
|
70
|
+
* unless `orgAdminGateBearerTokens`. Compared case-insensitively.
|
|
71
|
+
* Validated at load.
|
|
72
|
+
*/
|
|
73
|
+
orgAdminRoles?: string[];
|
|
74
|
+
/**
|
|
75
|
+
* Judge Frigg bearer-token callers by role like adopter-token callers.
|
|
76
|
+
* Default false: they keep their behaviour from before organization roles.
|
|
77
|
+
*/
|
|
78
|
+
orgAdminGateBearerTokens?: boolean;
|
|
79
|
+
authModes?: UserAuthModes;
|
|
80
|
+
jwtConfig?: AdopterJwtConfig;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* One person's membership of one organization (ADR-056 §3.6). `implicit` is
|
|
85
|
+
* true when it is only the legacy `IndividualUser.organizationId` pointer.
|
|
86
|
+
*/
|
|
87
|
+
export interface OrganizationMembership {
|
|
88
|
+
id: string | null;
|
|
89
|
+
individualUserId: string;
|
|
90
|
+
organizationUserId: string;
|
|
91
|
+
/** Defaults to `MEMBER`. */
|
|
92
|
+
orgRole: string;
|
|
93
|
+
createdAt?: Date;
|
|
94
|
+
implicit: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface OrganizationMembershipRepository {
|
|
98
|
+
/** The stored row or null: the legacy `organizationId` pointer is not read here. */
|
|
99
|
+
findMembership(
|
|
100
|
+
individualUserId: string,
|
|
101
|
+
organizationUserId: string
|
|
102
|
+
): Promise<OrganizationMembership | null>;
|
|
103
|
+
/** Idempotent: adds when absent, never changes an existing membership. */
|
|
104
|
+
addMembership(
|
|
105
|
+
individualUserId: string,
|
|
106
|
+
organizationUserId: string,
|
|
107
|
+
options?: { orgRole?: string | null }
|
|
108
|
+
): Promise<OrganizationMembership>;
|
|
109
|
+
/** Stored rows only, oldest first; legacy-pointer people are not here. */
|
|
110
|
+
listMembershipsForOrganization(
|
|
111
|
+
organizationUserId: string
|
|
112
|
+
): Promise<OrganizationMembership[]>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function createOrganizationMembershipRepository(): OrganizationMembershipRepository;
|
|
116
|
+
|
|
117
|
+
export class User {
|
|
118
|
+
/** The primary user's id; under `primary: 'organization'` the ACTIVE organization. */
|
|
119
|
+
getId(): string | undefined;
|
|
120
|
+
/** The organization this request acts in (token or `x-frigg-apporgid`), or null. */
|
|
121
|
+
getActiveOrganizationId(): string | null;
|
|
122
|
+
getAppUserId(): string | null;
|
|
123
|
+
getAppOrgId(): string | null;
|
|
124
|
+
getIndividualUser(): any;
|
|
125
|
+
getOrganizationUser(): any;
|
|
126
|
+
getPrimaryUser(): any;
|
|
127
|
+
/** The organization role from the adopter token for this request, or null. */
|
|
128
|
+
getOrgRole(): string | null;
|
|
129
|
+
setOrgRole(orgRole: string | null): void;
|
|
130
|
+
/** The stored `orgRole` of the membership of the active organization, or null. Used when the token carries no role. */
|
|
131
|
+
getMembershipRole(): string | null;
|
|
132
|
+
setMembershipRole(membershipRole: string | null): void;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
const { getLogger } = require('../logs');
|
|
2
|
+
|
|
3
|
+
const log = getLogger('frigg.user.adopter_jwt');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Normalises and validates `user.jwtConfig` from the app definition (ADR-056 §2).
|
|
7
|
+
* Called once at startup by the app definition loader and once per verifier,
|
|
8
|
+
* never per request.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const ASYMMETRIC_ALGORITHMS = ['ES256', 'ES384', 'RS256', 'RS384', 'RS512'];
|
|
12
|
+
const HMAC_ALGORITHMS = ['HS256', 'HS384', 'HS512'];
|
|
13
|
+
const SUPPORTED_ALGORITHMS = [...ASYMMETRIC_ALGORITHMS, ...HMAC_ALGORITHMS];
|
|
14
|
+
|
|
15
|
+
const DEFAULTS = Object.freeze({
|
|
16
|
+
jwksAlgorithms: Object.freeze(['ES256', 'RS256']),
|
|
17
|
+
secretAlgorithms: Object.freeze(['HS256']),
|
|
18
|
+
clockToleranceSec: 30,
|
|
19
|
+
userIdClaim: 'sub',
|
|
20
|
+
orgIdClaim: 'org_id',
|
|
21
|
+
roleClaim: 'org_role',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const isNonEmptyString = (value) =>
|
|
25
|
+
typeof value === 'string' && value.trim() !== '';
|
|
26
|
+
|
|
27
|
+
const hasAudience = (audience) =>
|
|
28
|
+
isNonEmptyString(audience) ||
|
|
29
|
+
(Array.isArray(audience) &&
|
|
30
|
+
audience.length > 0 &&
|
|
31
|
+
audience.every(isNonEmptyString));
|
|
32
|
+
|
|
33
|
+
const LOOPBACK_IPV4 = /^127(\.\d{1,3}){3}$/;
|
|
34
|
+
|
|
35
|
+
function isLoopbackHost(hostname) {
|
|
36
|
+
return (
|
|
37
|
+
hostname === 'localhost' ||
|
|
38
|
+
hostname === '[::1]' ||
|
|
39
|
+
LOOPBACK_IPV4.test(hostname)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The JWKS is the trust root: fetched over https, or over http only to the
|
|
45
|
+
* machine itself (a local identity provider in development).
|
|
46
|
+
*/
|
|
47
|
+
function assertJwksUri(jwksUri) {
|
|
48
|
+
let url;
|
|
49
|
+
try {
|
|
50
|
+
url = new URL(jwksUri);
|
|
51
|
+
} catch {
|
|
52
|
+
throw new Error('user.jwtConfig.jwksUri is not a valid URL');
|
|
53
|
+
}
|
|
54
|
+
if (url.protocol === 'https:') return;
|
|
55
|
+
if (url.protocol === 'http:' && isLoopbackHost(url.hostname)) return;
|
|
56
|
+
throw new Error(
|
|
57
|
+
'user.jwtConfig.jwksUri must use https (http is allowed only for localhost, 127.0.0.0/8 and ::1)'
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {Object} [jwtConfig] `userConfig.jwtConfig`
|
|
63
|
+
* @returns {{jwksUri?: string, secret?: string, issuer?: string,
|
|
64
|
+
* audience?: string|string[], algorithms: string[], clockToleranceSec: number,
|
|
65
|
+
* userIdClaim: string, orgIdClaim: string, roleClaim: string}}
|
|
66
|
+
* @throws {Error} When the config cannot verify any token safely.
|
|
67
|
+
*/
|
|
68
|
+
function resolveAdopterJwtConfig(jwtConfig) {
|
|
69
|
+
const config = jwtConfig && typeof jwtConfig === 'object' ? jwtConfig : {};
|
|
70
|
+
const hasJwks = isNonEmptyString(config.jwksUri);
|
|
71
|
+
const hasSecret = isNonEmptyString(config.secret);
|
|
72
|
+
|
|
73
|
+
if (!hasJwks && !hasSecret) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
'user.authModes.adopterJwt is enabled but user.jwtConfig has neither jwksUri nor secret'
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (hasJwks && hasSecret) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
'user.jwtConfig sets both jwksUri and secret; set one, so a token cannot choose which key family verifies it'
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (hasJwks) {
|
|
84
|
+
assertJwksUri(config.jwksUri);
|
|
85
|
+
// Without an audience, a token minted by the same issuer for another
|
|
86
|
+
// service verifies here. HMAC mode shares its secret with one issuer,
|
|
87
|
+
// so it stays lenient.
|
|
88
|
+
if (!hasAudience(config.audience)) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
'user.jwtConfig.audience is required when jwksUri is used'
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (config.algorithm !== undefined && config.algorithms !== undefined) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
'user.jwtConfig sets both algorithm and algorithms; use algorithms (algorithm is a deprecated alias)'
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const configured =
|
|
101
|
+
config.algorithms ??
|
|
102
|
+
(config.algorithm ? [config.algorithm] : undefined);
|
|
103
|
+
const algorithms =
|
|
104
|
+
configured ??
|
|
105
|
+
(hasSecret ? DEFAULTS.secretAlgorithms : DEFAULTS.jwksAlgorithms);
|
|
106
|
+
|
|
107
|
+
if (
|
|
108
|
+
!Array.isArray(algorithms) ||
|
|
109
|
+
algorithms.length === 0 ||
|
|
110
|
+
algorithms.some((alg) => !SUPPORTED_ALGORITHMS.includes(alg))
|
|
111
|
+
) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`user.jwtConfig.algorithms must be a non-empty list drawn from ${SUPPORTED_ALGORITHMS.join(
|
|
114
|
+
', '
|
|
115
|
+
)}`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
// A key family only verifies its own algorithms; mixing them is how
|
|
119
|
+
// algorithm-confusion attacks are built.
|
|
120
|
+
if (hasSecret && algorithms.some((alg) => !HMAC_ALGORITHMS.includes(alg))) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
'user.jwtConfig.algorithms may only list HS* algorithms when secret is used'
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
if (hasJwks && algorithms.some((alg) => HMAC_ALGORITHMS.includes(alg))) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
'user.jwtConfig.algorithms may not list HS* algorithms when jwksUri is used'
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const clockToleranceSec =
|
|
132
|
+
config.clockToleranceSec ?? DEFAULTS.clockToleranceSec;
|
|
133
|
+
if (!Number.isInteger(clockToleranceSec) || clockToleranceSec < 0) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
'user.jwtConfig.clockToleranceSec must be an integer >= 0'
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
jwksUri: hasJwks ? config.jwksUri : undefined,
|
|
141
|
+
secret: hasSecret ? config.secret : undefined,
|
|
142
|
+
issuer: config.issuer || undefined,
|
|
143
|
+
audience: config.audience || undefined,
|
|
144
|
+
algorithms,
|
|
145
|
+
clockToleranceSec,
|
|
146
|
+
userIdClaim: config.userIdClaim || DEFAULTS.userIdClaim,
|
|
147
|
+
orgIdClaim: config.orgIdClaim || DEFAULTS.orgIdClaim,
|
|
148
|
+
roleClaim: config.roleClaim || DEFAULTS.roleClaim,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Startup check: throws when `authModes.adopterJwt` is on and `jwtConfig`
|
|
154
|
+
* is unusable, and warns when a jwksUri has no issuer. A no-op when the mode
|
|
155
|
+
* is off, so apps that never enabled it are not affected by a stray `jwtConfig`.
|
|
156
|
+
*
|
|
157
|
+
* @param {Object|null} [userConfig] `appDefinition.user`
|
|
158
|
+
* @throws {Error}
|
|
159
|
+
*/
|
|
160
|
+
function assertAdopterJwtConfig(userConfig) {
|
|
161
|
+
if (userConfig?.authModes?.adopterJwt !== true) return;
|
|
162
|
+
const config = resolveAdopterJwtConfig(userConfig.jwtConfig);
|
|
163
|
+
if (config.jwksUri && !config.issuer) {
|
|
164
|
+
log.warn(
|
|
165
|
+
'Adopter JWT issuer is not set; any issuer on this JWKS is accepted',
|
|
166
|
+
{
|
|
167
|
+
eventName: `${log.name}.issuer_unset`,
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
module.exports = {
|
|
174
|
+
resolveAdopterJwtConfig,
|
|
175
|
+
assertAdopterJwtConfig,
|
|
176
|
+
SUPPORTED_ALGORITHMS,
|
|
177
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* eslint-disable camelcase -- the reason codes are snake_case by spec */
|
|
2
|
+
const Boom = require('@hapi/boom');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Every failure adopter-token authentication can produce, keyed by the stable
|
|
6
|
+
* reason code clients see in `error.data.reason`. Messages are fixed text:
|
|
7
|
+
* the token and its claims never reach a message, `data` or a log record.
|
|
8
|
+
*/
|
|
9
|
+
const ADOPTER_JWT_ERRORS = Object.freeze({
|
|
10
|
+
token_expired: Object.freeze({ status: 401, message: 'Token has expired' }),
|
|
11
|
+
token_not_yet_valid: Object.freeze({
|
|
12
|
+
status: 401,
|
|
13
|
+
message: 'Token is not yet valid',
|
|
14
|
+
}),
|
|
15
|
+
token_invalid_signature: Object.freeze({
|
|
16
|
+
status: 401,
|
|
17
|
+
message: 'Token signature could not be verified',
|
|
18
|
+
}),
|
|
19
|
+
token_wrong_issuer: Object.freeze({
|
|
20
|
+
status: 401,
|
|
21
|
+
message: 'Token issuer is not accepted',
|
|
22
|
+
}),
|
|
23
|
+
token_wrong_audience: Object.freeze({
|
|
24
|
+
status: 401,
|
|
25
|
+
message: 'Token audience is not accepted',
|
|
26
|
+
}),
|
|
27
|
+
token_missing_user_claim: Object.freeze({
|
|
28
|
+
status: 401,
|
|
29
|
+
message: 'Token does not identify a user',
|
|
30
|
+
}),
|
|
31
|
+
token_malformed: Object.freeze({
|
|
32
|
+
status: 401,
|
|
33
|
+
message: 'Token is malformed',
|
|
34
|
+
}),
|
|
35
|
+
// Our dependency failing, not the caller's token: not a 401, so a client
|
|
36
|
+
// does not discard a good session during a JWKS outage.
|
|
37
|
+
jwks_unavailable: Object.freeze({
|
|
38
|
+
status: 503,
|
|
39
|
+
message: 'Token verification keys are unavailable',
|
|
40
|
+
}),
|
|
41
|
+
jwt_config_invalid: Object.freeze({
|
|
42
|
+
status: 500,
|
|
43
|
+
message: 'Adopter JWT authentication is misconfigured',
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {keyof typeof ADOPTER_JWT_ERRORS} code
|
|
49
|
+
* @returns {Boom.Boom} with `data.reason` set to `code`
|
|
50
|
+
*/
|
|
51
|
+
function fail(code) {
|
|
52
|
+
const { status, message } = ADOPTER_JWT_ERRORS[code];
|
|
53
|
+
return new Boom.Boom(message, {
|
|
54
|
+
statusCode: status,
|
|
55
|
+
data: { reason: code },
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = { ADOPTER_JWT_ERRORS, fail };
|