@dereekb/firebase-server 13.11.2 → 13.11.4
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/index.cjs.js +29 -2
- package/index.esm.js +30 -3
- package/mailgun/package.json +9 -9
- package/model/index.cjs.js +330 -43
- package/model/index.esm.js +332 -46
- package/model/package.json +9 -9
- package/model/src/lib/notification/notification.action.server.d.ts +16 -1
- package/model/src/lib/notification/notification.module.d.ts +4 -0
- package/oidc/index.cjs.js +455 -38
- package/oidc/index.esm.js +453 -40
- package/oidc/package.json +10 -10
- package/oidc/src/lib/controller/oidc.interaction.controller.d.ts +3 -1
- package/oidc/src/lib/model/oidc/oidcmodel.action.server.d.ts +22 -1
- package/oidc/src/lib/model/oidc/oidcmodel.module.d.ts +6 -3
- package/oidc/src/lib/oidc.config.d.ts +82 -6
- package/oidc/src/lib/oidc.module.d.ts +1 -1
- package/oidc/src/lib/service/oidc.adapter.service.d.ts +5 -0
- package/oidc/src/lib/service/oidc.interaction.service.d.ts +7 -1
- package/oidc/src/lib/service/oidc.service.d.ts +31 -1
- package/oidc/src/lib/service/oidc.session-ttl.d.ts +85 -0
- package/package.json +10 -10
- package/src/lib/firestore/array.d.ts +1 -0
- package/src/lib/firestore/driver.accessor.batch.d.ts +1 -0
- package/src/lib/firestore/driver.accessor.default.d.ts +1 -0
- package/src/lib/firestore/driver.accessor.transaction.d.ts +1 -0
- package/src/lib/firestore/driver.query.d.ts +1 -0
- package/src/lib/firestore/increment.d.ts +1 -0
- package/src/lib/firestore/snapshot/snapshot.field.encrypt.d.ts +2 -0
- package/src/lib/nest/app.module.d.ts +1 -0
- package/src/lib/nest/auth/auth.module.d.ts +1 -0
- package/src/lib/nest/development/development.app.function.d.ts +1 -0
- package/src/lib/nest/development/development.function.d.ts +1 -0
- package/src/lib/nest/development/development.schedule.function.d.ts +1 -0
- package/src/lib/nest/development/development.schedule.function.error.d.ts +1 -0
- package/src/lib/nest/function/call.d.ts +1 -0
- package/src/lib/nest/function/context.d.ts +1 -0
- package/src/lib/nest/function/v2/blocking.d.ts +2 -0
- package/src/lib/nest/function/v2/call.d.ts +2 -0
- package/src/lib/nest/function/v2/event.d.ts +1 -0
- package/src/lib/nest/function/v2/schedule.d.ts +3 -0
- package/src/lib/nest/function/v2/taskqueue.d.ts +1 -0
- package/src/lib/nest/model/analytics.handler.d.ts +1 -0
- package/src/lib/nest/model/call.model.function.d.ts +1 -0
- package/src/lib/nest/model/create.model.function.d.ts +1 -0
- package/src/lib/nest/storage/storage.module.d.ts +1 -0
- package/test/package.json +11 -11
- package/zoho/package.json +9 -9
package/oidc/index.esm.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { createParamDecorator, Injectable, Inject, Optional, Logger, UnauthorizedException, Get, Param, Req, Res, Post, HttpCode, HttpStatus, Body, Controller, HttpException, All } from '@nestjs/common';
|
|
2
|
+
import { errors } from 'oidc-provider';
|
|
3
|
+
import { SECONDS_IN_MINUTE, SECONDS_IN_DAY, cachedGetter, unixDateTimeSecondsNumberToDate, unixDateTimeSecondsNumberForNow, selectiveFieldEncryptor, filterUndefinedValues, websiteUrlFromPaths, firstValue, hasHttpPrefix } from '@dereekb/util';
|
|
2
4
|
import { generateKeyPairSync, randomBytes } from 'node:crypto';
|
|
3
5
|
import { resolveEncryptionKey, encryptValue, decryptValue, createAesStringEncryptionProvider, isValidAES256GCMEncryptionSecret } from '@dereekb/nestjs';
|
|
4
|
-
import { where, iterateFirestoreDocumentSnapshotPairs, firestoreModelIdentity, snapshotConverterFunctions, optionalFirestoreDate, firestoreDate, firestoreEnum, firestorePassThroughField, AbstractFirestoreDocument, createOidcClientParamsType, deleteOidcClientParamsType, rotateOidcClientSecretParamsType, updateOidcClientParamsType, firestoreModelKey, oidcEntryIdentity, OIDC_ENTRY_CLIENT_TYPE, oidcEntriesByUserCodeQuery, oidcEntriesByUidQuery, oidcEntriesByGrantIdQuery, oidcEntryFirestoreCollection, callModelOidcScopeForCallType, CALL_MODEL_MISSING_OIDC_SCOPE_ERROR_CODE } from '@dereekb/firebase';
|
|
5
|
-
import { cachedGetter, unixDateTimeSecondsNumberToDate, unixDateTimeSecondsNumberForNow, selectiveFieldEncryptor, filterUndefinedValues, websiteUrlFromPaths, firstValue, hasHttpPrefix } from '@dereekb/util';
|
|
6
|
+
import { where, iterateFirestoreDocumentSnapshotPairs, firestoreModelIdentity, snapshotConverterFunctions, optionalFirestoreDate, firestoreDate, firestoreEnum, firestorePassThroughField, AbstractFirestoreDocument, createOidcClientParamsType, deleteOidcClientParamsType, deleteOidcTokenParamsType, rotateOidcClientSecretParamsType, updateOidcClientParamsType, firestoreModelKey, oidcEntryIdentity, OIDC_ENTRY_CLIENT_TYPE, oidcEntriesByUserCodeQuery, oidcEntriesByUidQuery, oidcEntriesByGrantIdQuery, oidcEntryFirestoreCollection, callModelOidcScopeForCallType, CALL_MODEL_MISSING_OIDC_SCOPE_ERROR_CODE } from '@dereekb/firebase';
|
|
6
7
|
import { firestoreEncryptedField, firebaseServerActionsContext, FirebaseServerEnvService, FIREBASE_FIRESTORE_CONTEXT_TOKEN, FirebaseServerFirestoreContextModule, forbiddenError } from '@dereekb/firebase-server';
|
|
7
8
|
import { nanoid } from 'nanoid';
|
|
9
|
+
import { safeToJsDate } from '@dereekb/date';
|
|
8
10
|
import { makeUrlSearchParamsString } from '@dereekb/util/fetch';
|
|
9
11
|
import { ConfigService, ConfigModule } from '@nestjs/config';
|
|
10
12
|
|
|
@@ -77,12 +79,20 @@ function _define_property$f(obj, key, value) {
|
|
|
77
79
|
return obj;
|
|
78
80
|
}
|
|
79
81
|
/**
|
|
80
|
-
* Default
|
|
82
|
+
* Default global ceiling for a client-requested login duration, in seconds. 90 days.
|
|
83
|
+
*/ var DEFAULT_MAX_REQUESTED_LOGIN_DURATION_SECONDS = 90 * SECONDS_IN_DAY;
|
|
84
|
+
/**
|
|
85
|
+
* Default global floor for a client-requested login duration, in seconds. 1 hour.
|
|
86
|
+
*/ var DEFAULT_MIN_REQUESTED_LOGIN_DURATION_SECONDS = 60 * SECONDS_IN_MINUTE;
|
|
87
|
+
/**
|
|
88
|
+
* Default token lifetimes: 15 min access tokens, 30-day refresh tokens, 30-day sessions/grants, 60 s auth codes.
|
|
81
89
|
*/ var DEFAULT_OIDC_TOKEN_LIFETIMES = {
|
|
82
|
-
accessToken:
|
|
83
|
-
idToken:
|
|
84
|
-
refreshToken: 30 *
|
|
85
|
-
authorizationCode:
|
|
90
|
+
accessToken: 15 * SECONDS_IN_MINUTE,
|
|
91
|
+
idToken: 60 * SECONDS_IN_MINUTE,
|
|
92
|
+
refreshToken: 30 * SECONDS_IN_DAY,
|
|
93
|
+
authorizationCode: SECONDS_IN_MINUTE,
|
|
94
|
+
session: 30 * SECONDS_IN_DAY,
|
|
95
|
+
grant: 30 * SECONDS_IN_DAY
|
|
86
96
|
};
|
|
87
97
|
// MARK: Config
|
|
88
98
|
/**
|
|
@@ -118,6 +128,26 @@ function _define_property$f(obj, key, value) {
|
|
|
118
128
|
* Token lifetime configuration.
|
|
119
129
|
*/ _define_property$f(this, "tokenLifetimes", void 0);
|
|
120
130
|
/**
|
|
131
|
+
* Maximum login duration (seconds) a client may request via the `dbx_session_ttl` auth-URL param.
|
|
132
|
+
*
|
|
133
|
+
* Acts as the global server cap for any per-request duration. A registered client can declare its own
|
|
134
|
+
* lower ceiling via the `dbx_max_session_ttl` client metadata field; the effective ceiling is
|
|
135
|
+
* `min(client.dbx_max_session_ttl, this)`.
|
|
136
|
+
*
|
|
137
|
+
* Defaults to {@link DEFAULT_MAX_REQUESTED_LOGIN_DURATION_SECONDS} (90 days).
|
|
138
|
+
*/ _define_property$f(this, "maxRequestedLoginDuration", void 0);
|
|
139
|
+
/**
|
|
140
|
+
* Minimum login duration (seconds) a client may request via the `dbx_session_ttl` auth-URL param.
|
|
141
|
+
*
|
|
142
|
+
* Requested values below this floor are clamped up. Prevents pathological 30-second sessions.
|
|
143
|
+
*
|
|
144
|
+
* Defaults to {@link DEFAULT_MIN_REQUESTED_LOGIN_DURATION_SECONDS} (1 hour).
|
|
145
|
+
*/ _define_property$f(this, "minRequestedLoginDuration", void 0);
|
|
146
|
+
/**
|
|
147
|
+
* Default login duration (seconds) used when a client does NOT pass the `dbx_session_ttl`
|
|
148
|
+
* auth-URL param. When undefined, falls back to {@link OidcTokenLifetimes.refreshToken}.
|
|
149
|
+
*/ _define_property$f(this, "defaultRequestedLoginDuration", void 0);
|
|
150
|
+
/**
|
|
121
151
|
* JWKS service configuration (encryption secret, rotated key max age).
|
|
122
152
|
*/ _define_property$f(this, "jwksServiceConfig", void 0);
|
|
123
153
|
/**
|
|
@@ -166,6 +196,33 @@ function _define_property$f(obj, key, value) {
|
|
|
166
196
|
*
|
|
167
197
|
* Defaults to `false`.
|
|
168
198
|
*/ _define_property$f(this, "registrationEnabled", void 0);
|
|
199
|
+
/**
|
|
200
|
+
* Whether the oidc-provider should trust upstream proxy headers
|
|
201
|
+
* (`X-Forwarded-Host`, `X-Forwarded-Proto`) when computing the request URL
|
|
202
|
+
* used to build resume/return URLs and discovery metadata absolute paths.
|
|
203
|
+
*
|
|
204
|
+
* Required when running behind a reverse proxy such as Firebase Hosting →
|
|
205
|
+
* Cloud Run / Cloud Functions, where the request `Host` header is the
|
|
206
|
+
* underlying Cloud Run host (e.g. `api-xxxxx-uc.a.run.app`) and not the
|
|
207
|
+
* canonical issuer host. Without this, the interaction `returnTo` URL is
|
|
208
|
+
* built off the Cloud Run host and the browser is redirected away from the
|
|
209
|
+
* issuer's domain after login — causing the interaction cookies (scoped to
|
|
210
|
+
* the canonical host) to be missing on the resume request and producing
|
|
211
|
+
* "authorization request has expired".
|
|
212
|
+
*
|
|
213
|
+
* Maps to `provider.proxy = <value>` on the underlying oidc-provider
|
|
214
|
+
* (which is the Koa `app.proxy` setting).
|
|
215
|
+
*
|
|
216
|
+
* Defaults to `'prod_only'` if the environment is `production`, otherwise `false`.
|
|
217
|
+
*/ _define_property$f(this, "trustProxy", void 0);
|
|
218
|
+
/**
|
|
219
|
+
* Whether to trust proxy headers in a non-production environment, such as the local environment.
|
|
220
|
+
*
|
|
221
|
+
* The dev environment typically does not require proxy headers, and setting
|
|
222
|
+
* `true` will result in errors.
|
|
223
|
+
*
|
|
224
|
+
* Defaults to `false`.
|
|
225
|
+
*/ _define_property$f(this, "trustProxyInNonProduction", void 0);
|
|
169
226
|
}
|
|
170
227
|
_create_class$d(OidcModuleConfig, null, [
|
|
171
228
|
{
|
|
@@ -203,6 +260,95 @@ function _define_property$f(obj, key, value) {
|
|
|
203
260
|
}
|
|
204
261
|
();
|
|
205
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Custom OIDC auth-URL parameter clients use to request a non-default login duration.
|
|
265
|
+
*
|
|
266
|
+
* Value is integer seconds. Subject to per-client and global server caps via {@link resolveLoginDurationSeconds}.
|
|
267
|
+
*/ var DBX_FIREBASE_SERVER_OIDC_SESSION_TTL_PARAM = 'dbx_session_ttl';
|
|
268
|
+
/**
|
|
269
|
+
* Custom oidc-provider client metadata field for a client's maximum requestable login duration (seconds).
|
|
270
|
+
*/ var DBX_FIREBASE_SERVER_OIDC_MAX_SESSION_TTL_CLIENT_METADATA = 'dbx_max_session_ttl';
|
|
271
|
+
/**
|
|
272
|
+
* Clamps a requested login duration into the allowed range.
|
|
273
|
+
*
|
|
274
|
+
* Resolution order:
|
|
275
|
+
* 1. Pick the requested value, falling back to the configured default when omitted.
|
|
276
|
+
* 2. Compute the effective ceiling as `min(serverMax, clientMax-or-Infinity)`.
|
|
277
|
+
* 3. Clamp the value to `[serverMin, ceiling]`.
|
|
278
|
+
*
|
|
279
|
+
* @param input - The clamp inputs (requested value, client cap, server bounds, default).
|
|
280
|
+
* @returns The clamped duration in seconds.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* resolveLoginDurationSeconds({
|
|
285
|
+
* requestedSeconds: 60 * 24 * 60 * 60, // 60 days
|
|
286
|
+
* clientMaxSeconds: 30 * 24 * 60 * 60, // 30 days client cap
|
|
287
|
+
* serverMaxSeconds: 90 * 24 * 60 * 60, // 90 days global cap
|
|
288
|
+
* serverMinSeconds: 60 * 60, // 1 hour floor
|
|
289
|
+
* defaultSeconds: 30 * 24 * 60 * 60
|
|
290
|
+
* }); // → 30 * 24 * 60 * 60 (clamped to client max)
|
|
291
|
+
* ```
|
|
292
|
+
*/ function resolveLoginDurationSeconds(input) {
|
|
293
|
+
var _input_requestedSeconds, _input_clientMaxSeconds;
|
|
294
|
+
var raw = (_input_requestedSeconds = input.requestedSeconds) !== null && _input_requestedSeconds !== void 0 ? _input_requestedSeconds : input.defaultSeconds;
|
|
295
|
+
var ceiling = Math.min(input.serverMaxSeconds, (_input_clientMaxSeconds = input.clientMaxSeconds) !== null && _input_clientMaxSeconds !== void 0 ? _input_clientMaxSeconds : Infinity);
|
|
296
|
+
return Math.max(input.serverMinSeconds, Math.min(raw, ceiling));
|
|
297
|
+
}
|
|
298
|
+
// MARK: Param parsing
|
|
299
|
+
/**
|
|
300
|
+
* Parses a raw `dbx_session_ttl` value (string or number, from URL query / form / persisted interaction params)
|
|
301
|
+
* into a positive integer number of seconds. Returns `undefined` when missing or invalid so the caller falls
|
|
302
|
+
* back to a default.
|
|
303
|
+
*
|
|
304
|
+
* @param raw - The raw value to parse.
|
|
305
|
+
* @returns The parsed positive integer seconds, or `undefined` when absent/invalid.
|
|
306
|
+
*/ function parseRequestedSessionTtlSeconds(raw) {
|
|
307
|
+
var result;
|
|
308
|
+
if (typeof raw === 'string' && raw.length > 0) {
|
|
309
|
+
var parsed = Number(raw);
|
|
310
|
+
if (Number.isFinite(parsed) && Number.isInteger(parsed) && parsed > 0) {
|
|
311
|
+
result = parsed;
|
|
312
|
+
}
|
|
313
|
+
} else if (typeof raw === 'number' && Number.isFinite(raw) && Number.isInteger(raw) && raw > 0) {
|
|
314
|
+
result = raw;
|
|
315
|
+
}
|
|
316
|
+
return result;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Reads {@link DBX_FIREBASE_SERVER_OIDC_SESSION_TTL_PARAM} from a KoaContextWithOIDC and parses it to a positive integer
|
|
320
|
+
* number of seconds. Returns `undefined` when missing or invalid (so the caller falls back to a default).
|
|
321
|
+
*
|
|
322
|
+
* @param ctx - The OIDC Koa context, or undefined.
|
|
323
|
+
* @returns The parsed positive integer seconds, or `undefined` when absent/invalid.
|
|
324
|
+
*/ function readRequestedSessionTtlSeconds(ctx) {
|
|
325
|
+
var _ctx_oidc;
|
|
326
|
+
var params = ctx === null || ctx === void 0 ? void 0 : (_ctx_oidc = ctx.oidc) === null || _ctx_oidc === void 0 ? void 0 : _ctx_oidc.params;
|
|
327
|
+
var raw = params != null ? params[DBX_FIREBASE_SERVER_OIDC_SESSION_TTL_PARAM] : undefined;
|
|
328
|
+
return parseRequestedSessionTtlSeconds(raw);
|
|
329
|
+
}
|
|
330
|
+
// MARK: Grant remaining time
|
|
331
|
+
/**
|
|
332
|
+
* Inspects oidc-provider entities on the context to find the resolved Grant expiry.
|
|
333
|
+
*
|
|
334
|
+
* Returns the remaining seconds until the Grant expires, or `undefined` when no Grant is bound to the context.
|
|
335
|
+
*
|
|
336
|
+
* @param ctx - The OIDC Koa context, or undefined.
|
|
337
|
+
* @returns The remaining seconds until grant expiry, or `undefined` when no grant is bound or it has expired.
|
|
338
|
+
*/ function readRemainingGrantSeconds(ctx) {
|
|
339
|
+
var _ctx_oidc_entities, _ctx_oidc;
|
|
340
|
+
var grant = ctx === null || ctx === void 0 ? void 0 : (_ctx_oidc = ctx.oidc) === null || _ctx_oidc === void 0 ? void 0 : (_ctx_oidc_entities = _ctx_oidc.entities) === null || _ctx_oidc_entities === void 0 ? void 0 : _ctx_oidc_entities.Grant;
|
|
341
|
+
var result;
|
|
342
|
+
if ((grant === null || grant === void 0 ? void 0 : grant.exp) != null && Number.isFinite(grant.exp)) {
|
|
343
|
+
var now = Math.floor(Date.now() / 1000);
|
|
344
|
+
var remaining = grant.exp - now;
|
|
345
|
+
if (remaining > 0) {
|
|
346
|
+
result = remaining;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return result;
|
|
350
|
+
}
|
|
351
|
+
|
|
206
352
|
/**
|
|
207
353
|
* Query for JwksKey documents with a specific status.
|
|
208
354
|
*
|
|
@@ -1607,7 +1753,8 @@ function _ts_generator$8(thisArg, body) {
|
|
|
1607
1753
|
createOidcClient: createOidcClientFactory(context),
|
|
1608
1754
|
updateOidcClient: updateOidcClientFactory(context),
|
|
1609
1755
|
rotateOidcClientSecret: rotateOidcClientSecretFactory(context),
|
|
1610
|
-
deleteOidcClient: deleteOidcClientFactory(context)
|
|
1756
|
+
deleteOidcClient: deleteOidcClientFactory(context),
|
|
1757
|
+
deleteOidcToken: deleteOidcTokenFactory(context)
|
|
1611
1758
|
};
|
|
1612
1759
|
}
|
|
1613
1760
|
// MARK: Actions
|
|
@@ -1746,6 +1893,59 @@ function _ts_generator$8(thisArg, body) {
|
|
|
1746
1893
|
})();
|
|
1747
1894
|
});
|
|
1748
1895
|
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Factory for the `deleteOidcToken` action.
|
|
1898
|
+
*
|
|
1899
|
+
* Asserts the target {@link OidcEntryDocument} is of type `Grant`, then delegates to
|
|
1900
|
+
* {@link OidcService.revokeGrant} so all grantable token entries (`AccessToken`,
|
|
1901
|
+
* `RefreshToken`, `AuthorizationCode`, `DeviceCode`, `BackchannelAuthenticationRequest`)
|
|
1902
|
+
* sharing the grant id are deleted along with the Grant entry itself.
|
|
1903
|
+
*
|
|
1904
|
+
* Per-user authorization (this user owns this Grant) is enforced upstream via the
|
|
1905
|
+
* model permission service before this action runs.
|
|
1906
|
+
*
|
|
1907
|
+
* @param context - the OIDC model server actions context
|
|
1908
|
+
* @returns a transform function factory for revoking OIDC grants
|
|
1909
|
+
*/ function deleteOidcTokenFactory(context) {
|
|
1910
|
+
var oidcService = context.oidcService, firebaseServerActionTransformFunctionFactory = context.firebaseServerActionTransformFunctionFactory;
|
|
1911
|
+
return firebaseServerActionTransformFunctionFactory(deleteOidcTokenParamsType, function(_params) {
|
|
1912
|
+
return _async_to_generator$8(function() {
|
|
1913
|
+
return _ts_generator$8(this, function(_state) {
|
|
1914
|
+
return [
|
|
1915
|
+
2,
|
|
1916
|
+
function(document) {
|
|
1917
|
+
return _async_to_generator$8(function() {
|
|
1918
|
+
var data;
|
|
1919
|
+
return _ts_generator$8(this, function(_state) {
|
|
1920
|
+
switch(_state.label){
|
|
1921
|
+
case 0:
|
|
1922
|
+
return [
|
|
1923
|
+
4,
|
|
1924
|
+
document.snapshotData()
|
|
1925
|
+
];
|
|
1926
|
+
case 1:
|
|
1927
|
+
data = _state.sent();
|
|
1928
|
+
if ((data === null || data === void 0 ? void 0 : data.type) !== 'Grant') {
|
|
1929
|
+
throw new Error('Only Grant entries can be revoked through this endpoint.');
|
|
1930
|
+
}
|
|
1931
|
+
return [
|
|
1932
|
+
4,
|
|
1933
|
+
oidcService.revokeGrant(document.id)
|
|
1934
|
+
];
|
|
1935
|
+
case 2:
|
|
1936
|
+
_state.sent();
|
|
1937
|
+
return [
|
|
1938
|
+
2
|
|
1939
|
+
];
|
|
1940
|
+
}
|
|
1941
|
+
});
|
|
1942
|
+
})();
|
|
1943
|
+
}
|
|
1944
|
+
];
|
|
1945
|
+
});
|
|
1946
|
+
})();
|
|
1947
|
+
});
|
|
1948
|
+
}
|
|
1749
1949
|
|
|
1750
1950
|
function asyncGeneratorStep$7(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1751
1951
|
try {
|
|
@@ -2005,6 +2205,9 @@ function _ts_generator$7(thisArg, body) {
|
|
|
2005
2205
|
if (params.jwks_uri) {
|
|
2006
2206
|
properties.jwks_uri = params.jwks_uri;
|
|
2007
2207
|
}
|
|
2208
|
+
if (params.dbx_max_session_ttl != null) {
|
|
2209
|
+
properties.dbx_max_session_ttl = params.dbx_max_session_ttl;
|
|
2210
|
+
}
|
|
2008
2211
|
// Merge any pre-validated metadata (e.g., inline jwks for private_key_jwt in tests)
|
|
2009
2212
|
if (validatedMetadata === null || validatedMetadata === void 0 ? void 0 : validatedMetadata.jwks) {
|
|
2010
2213
|
properties.jwks = validatedMetadata.jwks;
|
|
@@ -2062,7 +2265,7 @@ function _ts_generator$7(thisArg, body) {
|
|
|
2062
2265
|
* @throws When the client is not found.
|
|
2063
2266
|
*/ function updateClient(clientId, params) {
|
|
2064
2267
|
return _async_to_generator$7(function() {
|
|
2065
|
-
var provider, ProviderClient, existing, updatedMetadata, _params_logo_uri, _params_client_uri, client;
|
|
2268
|
+
var provider, ProviderClient, existing, updatedMetadata, _params_logo_uri, _params_client_uri, _params_dbx_max_session_ttl, client;
|
|
2066
2269
|
return _ts_generator$7(this, function(_state) {
|
|
2067
2270
|
switch(_state.label){
|
|
2068
2271
|
case 0:
|
|
@@ -2091,6 +2294,9 @@ function _ts_generator$7(thisArg, body) {
|
|
|
2091
2294
|
if (params.client_uri !== undefined) {
|
|
2092
2295
|
updatedMetadata.client_uri = (_params_client_uri = params.client_uri) !== null && _params_client_uri !== void 0 ? _params_client_uri : undefined;
|
|
2093
2296
|
}
|
|
2297
|
+
if (params.dbx_max_session_ttl !== undefined) {
|
|
2298
|
+
updatedMetadata.dbx_max_session_ttl = (_params_dbx_max_session_ttl = params.dbx_max_session_ttl) !== null && _params_dbx_max_session_ttl !== void 0 ? _params_dbx_max_session_ttl : undefined;
|
|
2299
|
+
}
|
|
2094
2300
|
// Mirrors oidc-provider's lib/helpers/add_client.js: re-validates and persists.
|
|
2095
2301
|
return [
|
|
2096
2302
|
4,
|
|
@@ -2273,13 +2479,15 @@ function _object_spread_props$1(target, source) {
|
|
|
2273
2479
|
}
|
|
2274
2480
|
// MARK: Provider Factories
|
|
2275
2481
|
/**
|
|
2276
|
-
* Factory that creates an {@link OidcModelServerActions} instance from the injected
|
|
2482
|
+
* Factory that creates an {@link OidcModelServerActions} instance from the injected services.
|
|
2277
2483
|
*
|
|
2278
|
-
* @param oidcClientService - the OIDC client service
|
|
2484
|
+
* @param oidcClientService - the OIDC client service for client CRUD actions
|
|
2485
|
+
* @param oidcService - the core OIDC service for grant revocation
|
|
2279
2486
|
* @returns the configured OidcModelServerActions instance
|
|
2280
|
-
*/ function oidcModelServerActionsFactory(oidcClientService) {
|
|
2487
|
+
*/ function oidcModelServerActionsFactory(oidcClientService, oidcService) {
|
|
2281
2488
|
var context = _object_spread_props$1(_object_spread$4({}, firebaseServerActionsContext()), {
|
|
2282
|
-
oidcClientService: oidcClientService
|
|
2489
|
+
oidcClientService: oidcClientService,
|
|
2490
|
+
oidcService: oidcService
|
|
2283
2491
|
});
|
|
2284
2492
|
return oidcModelServerActions(context);
|
|
2285
2493
|
}
|
|
@@ -2305,7 +2513,8 @@ function _object_spread_props$1(target, source) {
|
|
|
2305
2513
|
provide: OidcModelServerActions,
|
|
2306
2514
|
useFactory: oidcModelServerActionsFactory,
|
|
2307
2515
|
inject: [
|
|
2308
|
-
OidcClientService
|
|
2516
|
+
OidcClientService,
|
|
2517
|
+
OidcService
|
|
2309
2518
|
]
|
|
2310
2519
|
}
|
|
2311
2520
|
]
|
|
@@ -2497,13 +2706,14 @@ function _ts_generator$6(thisArg, body) {
|
|
|
2497
2706
|
// MARK: Adapter
|
|
2498
2707
|
/**
|
|
2499
2708
|
* Model types that support grantId-based revocation.
|
|
2500
|
-
*/ var
|
|
2709
|
+
*/ var GRANTABLE_MODEL_NAMES = [
|
|
2501
2710
|
'AccessToken',
|
|
2502
2711
|
'AuthorizationCode',
|
|
2503
2712
|
'RefreshToken',
|
|
2504
2713
|
'DeviceCode',
|
|
2505
2714
|
'BackchannelAuthenticationRequest'
|
|
2506
|
-
]
|
|
2715
|
+
];
|
|
2716
|
+
var GRANTABLE_MODELS = new Set(GRANTABLE_MODEL_NAMES);
|
|
2507
2717
|
/**
|
|
2508
2718
|
* Creates an oidc-provider adapter constructor backed by Firestore via {@link OidcServerFirestoreCollections}.
|
|
2509
2719
|
*
|
|
@@ -2534,22 +2744,44 @@ function _ts_generator$6(thisArg, body) {
|
|
|
2534
2744
|
key: "upsert",
|
|
2535
2745
|
value: function upsert(id, payload, expiresIn) {
|
|
2536
2746
|
return _async_to_generator$6(function() {
|
|
2537
|
-
var o, data, doc;
|
|
2747
|
+
var _payload_uid, _payload_clientId, o, uid, clientId, iat, createdAtIso, createdAt, data, doc;
|
|
2538
2748
|
return _ts_generator$6(this, function(_state) {
|
|
2539
2749
|
switch(_state.label){
|
|
2540
2750
|
case 0:
|
|
2541
2751
|
// Set ownership key for Client entries so firestore rules can restrict reads by owner.
|
|
2542
2752
|
// The firestoreOwnerKey is passed through the payload metadata by OidcClientService.
|
|
2543
2753
|
o = this.name === OIDC_ENTRY_CLIENT_TYPE ? payload.firestoreOwnerKey : undefined;
|
|
2754
|
+
// oidc-provider uses `accountId` as the user identifier on Grant, AccessToken,
|
|
2755
|
+
// RefreshToken, etc. — `payload.uid` is only populated on Session/Interaction.
|
|
2756
|
+
// Fall back to `accountId` so the indexed `uid` column works for all entry types.
|
|
2757
|
+
uid = (_payload_uid = payload.uid) !== null && _payload_uid !== void 0 ? _payload_uid : payload.accountId;
|
|
2758
|
+
// oidc-provider stores the OAuth client id as `clientId` on every grantable
|
|
2759
|
+
// model (Grant, AccessToken, RefreshToken, AuthorizationCode, DeviceCode, etc.).
|
|
2760
|
+
// Client entries themselves use `client_id` in the payload, so we read both.
|
|
2761
|
+
clientId = (_payload_clientId = payload.clientId) !== null && _payload_clientId !== void 0 ? _payload_clientId : payload.client_id;
|
|
2762
|
+
// Derive a stable `createdAt` from the payload so it survives upserts
|
|
2763
|
+
// (e.g. `consume`). Grant/AccessToken/RefreshToken/AuthorizationCode all
|
|
2764
|
+
// inherit `iat` (epoch seconds) from BaseToken; Client entries use
|
|
2765
|
+
// `created_at` (ISO string).
|
|
2766
|
+
iat = payload.iat;
|
|
2767
|
+
createdAtIso = payload.created_at;
|
|
2768
|
+
if (typeof iat === 'number') {
|
|
2769
|
+
createdAt = unixDateTimeSecondsNumberToDate(iat);
|
|
2770
|
+
} else if (createdAtIso) {
|
|
2771
|
+
createdAt = safeToJsDate(createdAtIso);
|
|
2772
|
+
}
|
|
2544
2773
|
data = _object_spread$3({
|
|
2545
2774
|
type: this.name,
|
|
2546
2775
|
payload: encryptionService.encryptAdapterPayload(payload),
|
|
2547
2776
|
o: o,
|
|
2548
|
-
uid:
|
|
2777
|
+
uid: uid,
|
|
2549
2778
|
grantId: payload.grantId,
|
|
2779
|
+
clientId: clientId,
|
|
2550
2780
|
userCode: payload.userCode,
|
|
2551
2781
|
consumed: payload.consumed
|
|
2552
|
-
},
|
|
2782
|
+
}, createdAt ? {
|
|
2783
|
+
createdAt: createdAt
|
|
2784
|
+
} : undefined, expiresIn ? {
|
|
2553
2785
|
expiresAt: unixDateTimeSecondsNumberToDate(unixDateTimeSecondsNumberForNow() + expiresIn)
|
|
2554
2786
|
} : undefined);
|
|
2555
2787
|
doc = this.collection.documentAccessor().loadDocumentForId(id);
|
|
@@ -3363,6 +3595,36 @@ function _ts_generator$5(thisArg, body) {
|
|
|
3363
3595
|
return this._getProvider();
|
|
3364
3596
|
}
|
|
3365
3597
|
},
|
|
3598
|
+
{
|
|
3599
|
+
// MARK: Login Duration
|
|
3600
|
+
/**
|
|
3601
|
+
* Resolves the login-duration TTL (seconds) for a Grant being created from a fresh consent submission.
|
|
3602
|
+
*
|
|
3603
|
+
* The Grant TTL configured on the oidc-provider only fires when oidc-provider's koa middleware drives
|
|
3604
|
+
* `grant.save()` (so `AsyncLocalStorage` carries the request context). Our consent flow saves grants
|
|
3605
|
+
* from a NestJS controller, so we resolve the TTL up-front and pre-set `grant.expiresIn` before saving.
|
|
3606
|
+
*
|
|
3607
|
+
* Mirrors the resolution used by the `Grant`/`Session` TTL functions in {@link buildProviderConfiguration}.
|
|
3608
|
+
*
|
|
3609
|
+
* @param requestedRawTtl - The raw `dbx_session_ttl` value from `interaction.params`, if any.
|
|
3610
|
+
* @param clientPayload - The persisted client metadata, used to read the per-client `dbx_max_session_ttl` cap.
|
|
3611
|
+
* @returns The resolved Grant TTL in seconds.
|
|
3612
|
+
*/ key: "resolveLoginDurationForGrant",
|
|
3613
|
+
value: function resolveLoginDurationForGrant(requestedRawTtl, clientPayload) {
|
|
3614
|
+
var _config_maxRequestedLoginDuration, _config_minRequestedLoginDuration, _config_defaultRequestedLoginDuration;
|
|
3615
|
+
var config = this.config;
|
|
3616
|
+
var serverMaxSeconds = (_config_maxRequestedLoginDuration = config.maxRequestedLoginDuration) !== null && _config_maxRequestedLoginDuration !== void 0 ? _config_maxRequestedLoginDuration : DEFAULT_MAX_REQUESTED_LOGIN_DURATION_SECONDS;
|
|
3617
|
+
var serverMinSeconds = (_config_minRequestedLoginDuration = config.minRequestedLoginDuration) !== null && _config_minRequestedLoginDuration !== void 0 ? _config_minRequestedLoginDuration : DEFAULT_MIN_REQUESTED_LOGIN_DURATION_SECONDS;
|
|
3618
|
+
var defaultSeconds = (_config_defaultRequestedLoginDuration = config.defaultRequestedLoginDuration) !== null && _config_defaultRequestedLoginDuration !== void 0 ? _config_defaultRequestedLoginDuration : config.tokenLifetimes.grant;
|
|
3619
|
+
return resolveLoginDurationSeconds({
|
|
3620
|
+
requestedSeconds: parseRequestedSessionTtlSeconds(requestedRawTtl),
|
|
3621
|
+
clientMaxSeconds: clientPayload === null || clientPayload === void 0 ? void 0 : clientPayload.dbx_max_session_ttl,
|
|
3622
|
+
serverMaxSeconds: serverMaxSeconds,
|
|
3623
|
+
serverMinSeconds: serverMinSeconds,
|
|
3624
|
+
defaultSeconds: defaultSeconds
|
|
3625
|
+
});
|
|
3626
|
+
}
|
|
3627
|
+
},
|
|
3366
3628
|
{
|
|
3367
3629
|
key: "verifyAccessToken",
|
|
3368
3630
|
value: // MARK: Token Verification
|
|
@@ -3440,6 +3702,67 @@ function _ts_generator$5(thisArg, body) {
|
|
|
3440
3702
|
}).call(this);
|
|
3441
3703
|
}
|
|
3442
3704
|
},
|
|
3705
|
+
{
|
|
3706
|
+
key: "revokeGrant",
|
|
3707
|
+
value: // MARK: Grant Revocation
|
|
3708
|
+
/**
|
|
3709
|
+
* Revokes a Grant entry and every grantable token entry that references it.
|
|
3710
|
+
*
|
|
3711
|
+
* Iterates through every grantable model (`AccessToken`, `AuthorizationCode`,
|
|
3712
|
+
* `RefreshToken`, `DeviceCode`, `BackchannelAuthenticationRequest`) and calls
|
|
3713
|
+
* the adapter's `revokeByGrantId` to delete all matching entries, then
|
|
3714
|
+
* deletes the Grant adapter entry itself. After this resolves, any token
|
|
3715
|
+
* referencing the grant is gone — `verifyAccessToken` returns `undefined`
|
|
3716
|
+
* and a `grant_type=refresh_token` exchange fails with `invalid_grant`.
|
|
3717
|
+
*
|
|
3718
|
+
* @param grantId - the grant id (and Grant adapter entry id) to revoke
|
|
3719
|
+
* @throws when the Grant entry does not exist
|
|
3720
|
+
*/ function revokeGrant(grantId) {
|
|
3721
|
+
return _async_to_generator$5(function() {
|
|
3722
|
+
var provider, ProviderGrant, existing;
|
|
3723
|
+
return _ts_generator$5(this, function(_state) {
|
|
3724
|
+
switch(_state.label){
|
|
3725
|
+
case 0:
|
|
3726
|
+
return [
|
|
3727
|
+
4,
|
|
3728
|
+
this.getProvider()
|
|
3729
|
+
];
|
|
3730
|
+
case 1:
|
|
3731
|
+
provider = _state.sent();
|
|
3732
|
+
ProviderGrant = provider.Grant;
|
|
3733
|
+
return [
|
|
3734
|
+
4,
|
|
3735
|
+
ProviderGrant.adapter.find(grantId)
|
|
3736
|
+
];
|
|
3737
|
+
case 2:
|
|
3738
|
+
existing = _state.sent();
|
|
3739
|
+
if (!existing) {
|
|
3740
|
+
throw new Error('Grant not found.');
|
|
3741
|
+
}
|
|
3742
|
+
return [
|
|
3743
|
+
4,
|
|
3744
|
+
Promise.all(GRANTABLE_MODEL_NAMES.map(function(modelName) {
|
|
3745
|
+
var _Model_adapter_revokeByGrantId, _Model_adapter;
|
|
3746
|
+
var Model = provider[modelName];
|
|
3747
|
+
return Model === null || Model === void 0 ? void 0 : (_Model_adapter = Model.adapter) === null || _Model_adapter === void 0 ? void 0 : (_Model_adapter_revokeByGrantId = _Model_adapter.revokeByGrantId) === null || _Model_adapter_revokeByGrantId === void 0 ? void 0 : _Model_adapter_revokeByGrantId.call(_Model_adapter, grantId);
|
|
3748
|
+
}))
|
|
3749
|
+
];
|
|
3750
|
+
case 3:
|
|
3751
|
+
_state.sent();
|
|
3752
|
+
return [
|
|
3753
|
+
4,
|
|
3754
|
+
ProviderGrant.adapter.destroy(grantId)
|
|
3755
|
+
];
|
|
3756
|
+
case 4:
|
|
3757
|
+
_state.sent();
|
|
3758
|
+
return [
|
|
3759
|
+
2
|
|
3760
|
+
];
|
|
3761
|
+
}
|
|
3762
|
+
});
|
|
3763
|
+
}).call(this);
|
|
3764
|
+
}
|
|
3765
|
+
},
|
|
3443
3766
|
{
|
|
3444
3767
|
key: "findClientPayload",
|
|
3445
3768
|
value: /**
|
|
@@ -3476,7 +3799,8 @@ function _ts_generator$5(thisArg, body) {
|
|
|
3476
3799
|
token_endpoint_auth_method: existing.token_endpoint_auth_method,
|
|
3477
3800
|
logo_uri: existing.logo_uri,
|
|
3478
3801
|
client_uri: existing.client_uri,
|
|
3479
|
-
created_at: existing.created_at
|
|
3802
|
+
created_at: existing.created_at,
|
|
3803
|
+
dbx_max_session_ttl: existing.dbx_max_session_ttl
|
|
3480
3804
|
};
|
|
3481
3805
|
}
|
|
3482
3806
|
return [
|
|
@@ -3501,8 +3825,21 @@ function _ts_generator$5(thisArg, body) {
|
|
|
3501
3825
|
*/ key: "buildProviderConfiguration",
|
|
3502
3826
|
value: function buildProviderConfiguration(cookieKeys) {
|
|
3503
3827
|
var _this = this;
|
|
3828
|
+
var _config_maxRequestedLoginDuration, _config_minRequestedLoginDuration;
|
|
3504
3829
|
var config = this.config;
|
|
3505
3830
|
var providerConfig = this.providerConfigService.providerConfig;
|
|
3831
|
+
var serverMaxSeconds = (_config_maxRequestedLoginDuration = config.maxRequestedLoginDuration) !== null && _config_maxRequestedLoginDuration !== void 0 ? _config_maxRequestedLoginDuration : DEFAULT_MAX_REQUESTED_LOGIN_DURATION_SECONDS;
|
|
3832
|
+
var serverMinSeconds = (_config_minRequestedLoginDuration = config.minRequestedLoginDuration) !== null && _config_minRequestedLoginDuration !== void 0 ? _config_minRequestedLoginDuration : DEFAULT_MIN_REQUESTED_LOGIN_DURATION_SECONDS;
|
|
3833
|
+
var overrideDefaultSeconds = config.defaultRequestedLoginDuration;
|
|
3834
|
+
var resolveDurationFromCtx = function resolveDurationFromCtx(ctx, client, perModelDefaultSeconds) {
|
|
3835
|
+
return resolveLoginDurationSeconds({
|
|
3836
|
+
requestedSeconds: readRequestedSessionTtlSeconds(ctx),
|
|
3837
|
+
clientMaxSeconds: client === null || client === void 0 ? void 0 : client.dbx_max_session_ttl,
|
|
3838
|
+
serverMaxSeconds: serverMaxSeconds,
|
|
3839
|
+
serverMinSeconds: serverMinSeconds,
|
|
3840
|
+
defaultSeconds: overrideDefaultSeconds !== null && overrideDefaultSeconds !== void 0 ? overrideDefaultSeconds : perModelDefaultSeconds
|
|
3841
|
+
});
|
|
3842
|
+
};
|
|
3506
3843
|
return _object_spread_props(_object_spread$2({
|
|
3507
3844
|
routes: _object_spread$2({}, this.providerConfigService.routes),
|
|
3508
3845
|
claims: _object_spread$2({}, providerConfig.claims),
|
|
@@ -3523,13 +3860,46 @@ function _ts_generator$5(thisArg, body) {
|
|
|
3523
3860
|
enabled: this.providerConfigService.oidcRegistrationRouteEnabled
|
|
3524
3861
|
}
|
|
3525
3862
|
},
|
|
3863
|
+
extraParams: [
|
|
3864
|
+
DBX_FIREBASE_SERVER_OIDC_SESSION_TTL_PARAM
|
|
3865
|
+
],
|
|
3866
|
+
extraClientMetadata: {
|
|
3867
|
+
properties: [
|
|
3868
|
+
DBX_FIREBASE_SERVER_OIDC_MAX_SESSION_TTL_CLIENT_METADATA
|
|
3869
|
+
],
|
|
3870
|
+
validator: function validator(_ctx, key, value) {
|
|
3871
|
+
if (key !== DBX_FIREBASE_SERVER_OIDC_MAX_SESSION_TTL_CLIENT_METADATA) {
|
|
3872
|
+
return;
|
|
3873
|
+
}
|
|
3874
|
+
if (value === undefined || value === null) {
|
|
3875
|
+
return;
|
|
3876
|
+
}
|
|
3877
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value <= 0) {
|
|
3878
|
+
throw new errors.InvalidClientMetadata("".concat(DBX_FIREBASE_SERVER_OIDC_MAX_SESSION_TTL_CLIENT_METADATA, " must be a positive integer (seconds)."));
|
|
3879
|
+
}
|
|
3880
|
+
if (value > serverMaxSeconds) {
|
|
3881
|
+
throw new errors.InvalidClientMetadata("".concat(DBX_FIREBASE_SERVER_OIDC_MAX_SESSION_TTL_CLIENT_METADATA, " cannot exceed the server max of ").concat(serverMaxSeconds, " seconds."));
|
|
3882
|
+
}
|
|
3883
|
+
}
|
|
3884
|
+
},
|
|
3526
3885
|
ttl: {
|
|
3527
3886
|
AccessToken: config.tokenLifetimes.accessToken,
|
|
3528
3887
|
IdToken: config.tokenLifetimes.idToken,
|
|
3529
3888
|
AuthorizationCode: config.tokenLifetimes.authorizationCode,
|
|
3530
|
-
RefreshToken:
|
|
3531
|
-
|
|
3532
|
-
|
|
3889
|
+
RefreshToken: function RefreshToken(ctx, _refreshToken, _client) {
|
|
3890
|
+
// The token endpoint's ctx.oidc.params holds the token-request body (code, code_verifier, …),
|
|
3891
|
+
// not the original auth params — `dbx_session_ttl` is no longer reachable here. The Grant
|
|
3892
|
+
// entity is bound on both initial issuance (authorization_code → token) and rotation
|
|
3893
|
+
// (refresh_token → token), and its `exp` already encodes the resolved login duration.
|
|
3894
|
+
var remaining = readRemainingGrantSeconds(ctx);
|
|
3895
|
+
return Math.min(remaining !== null && remaining !== void 0 ? remaining : config.tokenLifetimes.refreshToken, config.tokenLifetimes.refreshToken);
|
|
3896
|
+
},
|
|
3897
|
+
Session: function Session(ctx, _session) {
|
|
3898
|
+
return resolveDurationFromCtx(ctx, undefined, config.tokenLifetimes.session);
|
|
3899
|
+
},
|
|
3900
|
+
Grant: function Grant(ctx, _grant, client) {
|
|
3901
|
+
return resolveDurationFromCtx(ctx, client, config.tokenLifetimes.grant);
|
|
3902
|
+
},
|
|
3533
3903
|
Interaction: 60 * 60,
|
|
3534
3904
|
DeviceCode: 10 * 60
|
|
3535
3905
|
},
|
|
@@ -3648,7 +4018,7 @@ function _ts_generator$5(thisArg, body) {
|
|
|
3648
4018
|
value: // MARK: Internal
|
|
3649
4019
|
function _buildProvider() {
|
|
3650
4020
|
return _async_to_generator$5(function() {
|
|
3651
|
-
var _this, config, findAccount, signingKey, result, getEncryptionKey, cookieKey, adapterFactory, providerConfiguration, _ref, ProviderClass, provider;
|
|
4021
|
+
var _this, _config_trustProxy, config, findAccount, signingKey, result, getEncryptionKey, cookieKey, adapterFactory, providerConfiguration, _ref, ProviderClass, provider;
|
|
3652
4022
|
return _ts_generator$5(this, function(_state) {
|
|
3653
4023
|
switch(_state.label){
|
|
3654
4024
|
case 0:
|
|
@@ -3699,6 +4069,12 @@ function _ts_generator$5(thisArg, body) {
|
|
|
3699
4069
|
]
|
|
3700
4070
|
}
|
|
3701
4071
|
}));
|
|
4072
|
+
// Trust upstream X-Forwarded-* headers when running behind a reverse proxy
|
|
4073
|
+
// (e.g. Firebase Hosting → Cloud Run). Without this, oidc-provider builds
|
|
4074
|
+
// the interaction `returnTo` URL off the Cloud Run host instead of the
|
|
4075
|
+
// issuer's canonical host, so cookies set on the issuer host are not sent
|
|
4076
|
+
// on resume → "authorization request has expired".
|
|
4077
|
+
provider.proxy = (_config_trustProxy = config.trustProxy) !== null && _config_trustProxy !== void 0 ? _config_trustProxy : true;
|
|
3702
4078
|
if (config.suppressBodyParserWarning) ;
|
|
3703
4079
|
return [
|
|
3704
4080
|
2,
|
|
@@ -4411,13 +4787,20 @@ function _ts_generator$3(thisArg, body) {
|
|
|
4411
4787
|
value: /**
|
|
4412
4788
|
* Finds an existing grant by ID, or creates a new one.
|
|
4413
4789
|
*
|
|
4790
|
+
* For new grants, optionally pre-set `expiresIn` so {@link Grant#save} writes the requested TTL
|
|
4791
|
+
* instead of falling through to the configured Grant TTL function (which cannot read the original
|
|
4792
|
+
* `dbx_session_ttl` request param when save is driven from a NestJS controller — see
|
|
4793
|
+
* {@link OidcService#resolveLoginDurationForGrant}).
|
|
4794
|
+
*
|
|
4414
4795
|
* @param grantId - the existing grant ID to look up, or undefined to create a new grant
|
|
4415
4796
|
* @param accountId - the account ID for creating a new grant
|
|
4416
4797
|
* @param clientId - the client ID for creating a new grant
|
|
4798
|
+
* @param expiresInSeconds - optional TTL (seconds) to assign to a newly-created grant
|
|
4417
4799
|
* @returns the found or newly created grant
|
|
4418
|
-
*/
|
|
4800
|
+
*/ // eslint-disable-next-line @typescript-eslint/max-params -- positional args mirror the existing call sites
|
|
4801
|
+
function findOrCreateGrant(grantId, accountId, clientId, expiresInSeconds) {
|
|
4419
4802
|
return _async_to_generator$3(function() {
|
|
4420
|
-
var provider, grant, found;
|
|
4803
|
+
var provider, grant, found, grantInit;
|
|
4421
4804
|
return _ts_generator$3(this, function(_state) {
|
|
4422
4805
|
switch(_state.label){
|
|
4423
4806
|
case 0:
|
|
@@ -4446,10 +4829,14 @@ function _ts_generator$3(thisArg, body) {
|
|
|
4446
4829
|
4
|
|
4447
4830
|
];
|
|
4448
4831
|
case 3:
|
|
4449
|
-
|
|
4832
|
+
grantInit = {
|
|
4450
4833
|
accountId: accountId,
|
|
4451
4834
|
clientId: clientId
|
|
4452
|
-
}
|
|
4835
|
+
};
|
|
4836
|
+
if (expiresInSeconds != null) {
|
|
4837
|
+
grantInit.expiresIn = expiresInSeconds;
|
|
4838
|
+
}
|
|
4839
|
+
grant = new provider.Grant(grantInit);
|
|
4453
4840
|
_state.label = 4;
|
|
4454
4841
|
case 4:
|
|
4455
4842
|
return [
|
|
@@ -4686,14 +5073,16 @@ function _ts_generator$2(thisArg, body) {
|
|
|
4686
5073
|
* Firebase Auth ID token and bypass the oidc-provider interaction cookie
|
|
4687
5074
|
* (which is scoped to the frontend path set by `interactions.url`).
|
|
4688
5075
|
*/ var OidcInteractionController = /*#__PURE__*/ function() {
|
|
4689
|
-
function OidcInteractionController(oidcInteractionService, oidcProviderConfigService, accountService) {
|
|
5076
|
+
function OidcInteractionController(oidcInteractionService, oidcProviderConfigService, accountService, oidcService) {
|
|
4690
5077
|
_class_call_check$2(this, OidcInteractionController);
|
|
4691
5078
|
_define_property$3(this, "oidcInteractionService", void 0);
|
|
4692
5079
|
_define_property$3(this, "oidcProviderConfigService", void 0);
|
|
4693
5080
|
_define_property$3(this, "accountService", void 0);
|
|
5081
|
+
_define_property$3(this, "oidcService", void 0);
|
|
4694
5082
|
this.oidcInteractionService = oidcInteractionService;
|
|
4695
5083
|
this.oidcProviderConfigService = oidcProviderConfigService;
|
|
4696
5084
|
this.accountService = accountService;
|
|
5085
|
+
this.oidcService = oidcService;
|
|
4697
5086
|
}
|
|
4698
5087
|
_create_class$2(OidcInteractionController, [
|
|
4699
5088
|
{
|
|
@@ -4827,7 +5216,7 @@ function _ts_generator$2(thisArg, body) {
|
|
|
4827
5216
|
* @throws {HttpException} 400 when the consent interaction cannot be completed.
|
|
4828
5217
|
*/ function postConsent(uid, body, res) {
|
|
4829
5218
|
return _async_to_generator$2(function() {
|
|
4830
|
-
var _ref, redirectTo, interaction, prompt, params, session, grant, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, indicator, scopes, grantId, redirectTo1;
|
|
5219
|
+
var _ref, _ref1, redirectTo, interaction, prompt, params, session, clientId, requestedRawTtl, clientPayload, clientMaxSessionTtl, expiresInSeconds, grant, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, indicator, scopes, grantId, redirectTo1;
|
|
4831
5220
|
return _ts_generator$2(this, function(_state) {
|
|
4832
5221
|
switch(_state.label){
|
|
4833
5222
|
case 0:
|
|
@@ -4841,9 +5230,9 @@ function _ts_generator$2(thisArg, body) {
|
|
|
4841
5230
|
case 2:
|
|
4842
5231
|
_state.trys.push([
|
|
4843
5232
|
2,
|
|
4844
|
-
|
|
5233
|
+
10,
|
|
4845
5234
|
,
|
|
4846
|
-
|
|
5235
|
+
11
|
|
4847
5236
|
]);
|
|
4848
5237
|
if (!!body.approved) return [
|
|
4849
5238
|
3,
|
|
@@ -4874,11 +5263,28 @@ function _ts_generator$2(thisArg, body) {
|
|
|
4874
5263
|
case 5:
|
|
4875
5264
|
interaction = _state.sent();
|
|
4876
5265
|
prompt = interaction.prompt, params = interaction.params, session = interaction.session;
|
|
5266
|
+
clientId = params.client_id;
|
|
5267
|
+
// Resolve the requested login duration up-front. The configured Grant TTL function (in
|
|
5268
|
+
// OidcService.buildProviderConfiguration) only fires when oidc-provider's koa middleware
|
|
5269
|
+
// drives `grant.save()`, so its `ctx.oidc.params` lookup of `dbx_session_ttl` returns
|
|
5270
|
+
// undefined when the consent submit runs in this controller. We pre-set `expiresIn` on
|
|
5271
|
+
// newly-created grants so they persist with the correct TTL.
|
|
5272
|
+
requestedRawTtl = params[DBX_FIREBASE_SERVER_OIDC_SESSION_TTL_PARAM];
|
|
4877
5273
|
return [
|
|
4878
5274
|
4,
|
|
4879
|
-
this.
|
|
5275
|
+
this.oidcService.findClientPayload(clientId)
|
|
4880
5276
|
];
|
|
4881
5277
|
case 6:
|
|
5278
|
+
clientPayload = _state.sent();
|
|
5279
|
+
clientMaxSessionTtl = (_ref = clientPayload === null || clientPayload === void 0 ? void 0 : clientPayload.dbx_max_session_ttl) !== null && _ref !== void 0 ? _ref : undefined;
|
|
5280
|
+
expiresInSeconds = this.oidcService.resolveLoginDurationForGrant(requestedRawTtl, {
|
|
5281
|
+
dbx_max_session_ttl: clientMaxSessionTtl
|
|
5282
|
+
});
|
|
5283
|
+
return [
|
|
5284
|
+
4,
|
|
5285
|
+
this.oidcInteractionService.findOrCreateGrant(interaction.grantId, (_ref1 = session === null || session === void 0 ? void 0 : session.accountId) !== null && _ref1 !== void 0 ? _ref1 : '', clientId, expiresInSeconds)
|
|
5286
|
+
];
|
|
5287
|
+
case 7:
|
|
4882
5288
|
grant = _state.sent();
|
|
4883
5289
|
if (prompt.details.missingOIDCScope) {
|
|
4884
5290
|
grant.addOIDCScope(prompt.details.missingOIDCScope.join(' '));
|
|
@@ -4912,7 +5318,7 @@ function _ts_generator$2(thisArg, body) {
|
|
|
4912
5318
|
4,
|
|
4913
5319
|
grant.save()
|
|
4914
5320
|
];
|
|
4915
|
-
case
|
|
5321
|
+
case 8:
|
|
4916
5322
|
grantId = _state.sent();
|
|
4917
5323
|
return [
|
|
4918
5324
|
4,
|
|
@@ -4924,19 +5330,19 @@ function _ts_generator$2(thisArg, body) {
|
|
|
4924
5330
|
mergeWithLastSubmission: true
|
|
4925
5331
|
})
|
|
4926
5332
|
];
|
|
4927
|
-
case
|
|
5333
|
+
case 9:
|
|
4928
5334
|
redirectTo1 = _state.sent();
|
|
4929
5335
|
res.json({
|
|
4930
5336
|
redirectTo: redirectTo1
|
|
4931
5337
|
});
|
|
4932
5338
|
return [
|
|
4933
5339
|
3,
|
|
4934
|
-
|
|
5340
|
+
11
|
|
4935
5341
|
];
|
|
4936
|
-
case
|
|
5342
|
+
case 10:
|
|
4937
5343
|
_state.sent();
|
|
4938
5344
|
throw new HttpException('Consent interaction failed', HttpStatus.BAD_REQUEST);
|
|
4939
|
-
case
|
|
5345
|
+
case 11:
|
|
4940
5346
|
return [
|
|
4941
5347
|
2
|
|
4942
5348
|
];
|
|
@@ -5015,7 +5421,8 @@ OidcInteractionController = __decorate([
|
|
|
5015
5421
|
Controller('interaction'),
|
|
5016
5422
|
__param(0, Inject(OidcInteractionService)),
|
|
5017
5423
|
__param(1, Inject(OidcProviderConfigService)),
|
|
5018
|
-
__param(2, Inject(OidcAccountService))
|
|
5424
|
+
__param(2, Inject(OidcAccountService)),
|
|
5425
|
+
__param(3, Inject(OidcService))
|
|
5019
5426
|
], OidcInteractionController);
|
|
5020
5427
|
|
|
5021
5428
|
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
@@ -5687,6 +6094,8 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
5687
6094
|
appOAuthConsentUrlPart: DEFAULT_APP_OAUTH_CONSENT_PATH_PART,
|
|
5688
6095
|
appOAuthInteractionPath: DEFAULT_APP_OAUTH_INTERACTION_PATH,
|
|
5689
6096
|
tokenLifetimes: DEFAULT_OIDC_TOKEN_LIFETIMES,
|
|
6097
|
+
trustProxy: envService.isProduction,
|
|
6098
|
+
trustProxyInNonProduction: false,
|
|
5690
6099
|
jwksServiceConfig: {
|
|
5691
6100
|
encryptionSecret: encryptionSecret
|
|
5692
6101
|
},
|
|
@@ -5743,6 +6152,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
5743
6152
|
],
|
|
5744
6153
|
exports: [
|
|
5745
6154
|
OidcClientService,
|
|
6155
|
+
OidcService,
|
|
5746
6156
|
OidcModuleConfig,
|
|
5747
6157
|
OidcAuthMiddlewareConfig,
|
|
5748
6158
|
OidcServerFirestoreCollections
|
|
@@ -5759,6 +6169,9 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
5759
6169
|
var result = moduleConfig;
|
|
5760
6170
|
if (config) {
|
|
5761
6171
|
result = _object_spread({}, moduleConfig, config);
|
|
6172
|
+
if (config.trustProxyInNonProduction && !envService.isProduction) {
|
|
6173
|
+
result.trustProxy = true;
|
|
6174
|
+
}
|
|
5762
6175
|
}
|
|
5763
6176
|
return result;
|
|
5764
6177
|
}
|
|
@@ -5845,4 +6258,4 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
5845
6258
|
return fn;
|
|
5846
6259
|
}
|
|
5847
6260
|
|
|
5848
|
-
export { DEFAULT_APP_OAUTH_CONSENT_PATH_PART, DEFAULT_APP_OAUTH_INTERACTION_PATH, DEFAULT_APP_OAUTH_LOGIN_PATH_PART, DEFAULT_OIDC_CODE_CHALLENGE_METHODS, DEFAULT_OIDC_ID_TOKEN_SIGNING_ALG_VALUES, DEFAULT_OIDC_ISSUER_PATH, DEFAULT_OIDC_ROUTES, DEFAULT_OIDC_SUBJECT_TYPES, DEFAULT_OIDC_TOKEN_ENDPOINT_AUTH_METHODS, DEFAULT_OIDC_TOKEN_LIFETIMES, DEFAULT_ROTATED_KEY_MAX_AGE, FIREBASE_SERVER_OIDC_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE, JwksFirestoreCollections, JwksKeyDocument, JwksService, JwksServiceConfig, JwksServiceStorageConfig, OIDC_ENCRYPTED_PAYLOAD_FIELDS, OIDC_JWKS_ENCRYPTION_SECRET_ENV_KEY, OidcAccountService, OidcAccountServiceDelegate, OidcAccountServiceUserContext, OidcAuth, OidcAuthBearerTokenMiddleware, OidcAuthMiddlewareConfig, OidcClientService, OidcEncryptionService, OidcInteractionController, OidcInteractionService, OidcModelServerActions, OidcModuleConfig, OidcProviderConfigService, OidcProviderController, OidcServerFirestoreCollections, OidcService, OidcWellKnownController, activeJwksKeysQuery, appOidcModelModuleMetadata, applyOidcAuthMiddleware, createAdapterFactory, createOidcClientFactory, deleteOidcClientFactory, getOidcScopesFromRequest, jwksKeyCollectionReference, jwksKeyConverter, jwksKeyFirestoreCollection, jwksKeyIdentity, jwksKeysWithStatusQuery, nonRetiredJwksKeysQuery, oidcCallModelScopePreAssert, oidcFirestoreCollectionsFactory, oidcModelServerActions, oidcModelServerActionsFactory, oidcModuleConfigFactory, oidcModuleMetadata, rotateOidcClientSecretFactory, rotatedJwksKeysQuery, updateOidcClientFactory };
|
|
6261
|
+
export { DEFAULT_APP_OAUTH_CONSENT_PATH_PART, DEFAULT_APP_OAUTH_INTERACTION_PATH, DEFAULT_APP_OAUTH_LOGIN_PATH_PART, DEFAULT_MAX_REQUESTED_LOGIN_DURATION_SECONDS, DEFAULT_MIN_REQUESTED_LOGIN_DURATION_SECONDS, DEFAULT_OIDC_CODE_CHALLENGE_METHODS, DEFAULT_OIDC_ID_TOKEN_SIGNING_ALG_VALUES, DEFAULT_OIDC_ISSUER_PATH, DEFAULT_OIDC_ROUTES, DEFAULT_OIDC_SUBJECT_TYPES, DEFAULT_OIDC_TOKEN_ENDPOINT_AUTH_METHODS, DEFAULT_OIDC_TOKEN_LIFETIMES, DEFAULT_ROTATED_KEY_MAX_AGE, FIREBASE_SERVER_OIDC_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE, GRANTABLE_MODEL_NAMES, JwksFirestoreCollections, JwksKeyDocument, JwksService, JwksServiceConfig, JwksServiceStorageConfig, OIDC_ENCRYPTED_PAYLOAD_FIELDS, OIDC_JWKS_ENCRYPTION_SECRET_ENV_KEY, OidcAccountService, OidcAccountServiceDelegate, OidcAccountServiceUserContext, OidcAuth, OidcAuthBearerTokenMiddleware, OidcAuthMiddlewareConfig, OidcClientService, OidcEncryptionService, OidcInteractionController, OidcInteractionService, OidcModelServerActions, OidcModuleConfig, OidcProviderConfigService, OidcProviderController, OidcServerFirestoreCollections, OidcService, OidcWellKnownController, activeJwksKeysQuery, appOidcModelModuleMetadata, applyOidcAuthMiddleware, createAdapterFactory, createOidcClientFactory, deleteOidcClientFactory, deleteOidcTokenFactory, getOidcScopesFromRequest, jwksKeyCollectionReference, jwksKeyConverter, jwksKeyFirestoreCollection, jwksKeyIdentity, jwksKeysWithStatusQuery, nonRetiredJwksKeysQuery, oidcCallModelScopePreAssert, oidcFirestoreCollectionsFactory, oidcModelServerActions, oidcModelServerActionsFactory, oidcModuleConfigFactory, oidcModuleMetadata, rotateOidcClientSecretFactory, rotatedJwksKeysQuery, updateOidcClientFactory };
|