mongodb 6.6.2 → 6.7.0-dev.20240530.sha.f56938f
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/lib/client-side-encryption/providers/azure.js +21 -6
- package/lib/client-side-encryption/providers/azure.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +24 -16
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +78 -0
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +74 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +74 -135
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/command_builders.js +45 -0
- package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +46 -0
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +122 -0
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/machine_workflow.js +107 -0
- package/lib/cmap/auth/mongodb_oidc/machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_cache.js +52 -0
- package/lib/cmap/auth/mongodb_oidc/token_cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +34 -0
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc.js +26 -24
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
- package/lib/cmap/auth/providers.js +0 -1
- package/lib/cmap/auth/providers.js.map +1 -1
- package/lib/cmap/connect.js +4 -4
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +1 -1
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/connection_string.js +3 -0
- package/lib/connection_string.js.map +1 -1
- package/lib/error.js +57 -2
- package/lib/error.js.map +1 -1
- package/lib/index.js +5 -3
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +1 -1
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_client_auth_providers.js +34 -4
- package/lib/mongo_client_auth_providers.js.map +1 -1
- package/lib/sdam/server_description.js +10 -4
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sessions.js +10 -0
- package/lib/sessions.js.map +1 -1
- package/lib/utils.js +32 -2
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +115 -25
- package/package.json +6 -5
- package/src/client-side-encryption/providers/azure.ts +21 -10
- package/src/cmap/auth/mongo_credentials.ts +41 -34
- package/src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts +82 -0
- package/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts +85 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +96 -204
- package/src/cmap/auth/mongodb_oidc/command_builders.ts +54 -0
- package/src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts +53 -0
- package/src/cmap/auth/mongodb_oidc/human_callback_workflow.ts +142 -0
- package/src/cmap/auth/mongodb_oidc/machine_workflow.ts +137 -0
- package/src/cmap/auth/mongodb_oidc/token_cache.ts +62 -0
- package/src/cmap/auth/mongodb_oidc/token_machine_workflow.ts +34 -0
- package/src/cmap/auth/mongodb_oidc.ts +79 -49
- package/src/cmap/auth/providers.ts +0 -1
- package/src/cmap/connect.ts +14 -4
- package/src/cmap/connection.ts +1 -0
- package/src/cmap/connection_pool.ts +2 -1
- package/src/connection_string.ts +3 -0
- package/src/error.ts +58 -1
- package/src/index.ts +8 -4
- package/src/mongo_client.ts +4 -1
- package/src/mongo_client_auth_providers.ts +44 -6
- package/src/sdam/server_description.ts +13 -4
- package/src/sessions.ts +10 -0
- package/src/utils.ts +33 -0
- package/lib/client-side-encryption/providers/utils.js +0 -35
- package/lib/client-side-encryption/providers/utils.js.map +0 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +0 -30
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +0 -1
- package/lib/cmap/auth/mongodb_oidc/azure_service_workflow.js +0 -73
- package/lib/cmap/auth/mongodb_oidc/azure_service_workflow.js.map +0 -1
- package/lib/cmap/auth/mongodb_oidc/azure_token_cache.js +0 -49
- package/lib/cmap/auth/mongodb_oidc/azure_token_cache.js.map +0 -1
- package/lib/cmap/auth/mongodb_oidc/cache.js +0 -55
- package/lib/cmap/auth/mongodb_oidc/cache.js.map +0 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +0 -90
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +0 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +0 -43
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +0 -1
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js +0 -62
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js.map +0 -1
- package/src/client-side-encryption/providers/utils.ts +0 -37
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +0 -29
- package/src/cmap/auth/mongodb_oidc/azure_service_workflow.ts +0 -86
- package/src/cmap/auth/mongodb_oidc/azure_token_cache.ts +0 -51
- package/src/cmap/auth/mongodb_oidc/cache.ts +0 -63
- package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +0 -115
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +0 -49
- package/src/cmap/auth/mongodb_oidc/token_entry_cache.ts +0 -77
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { type AuthProvider } from './cmap/auth/auth_provider';
|
|
2
2
|
import { GSSAPI } from './cmap/auth/gssapi';
|
|
3
|
+
import { type AuthMechanismProperties } from './cmap/auth/mongo_credentials';
|
|
3
4
|
import { MongoCR } from './cmap/auth/mongocr';
|
|
4
5
|
import { MongoDBAWS } from './cmap/auth/mongodb_aws';
|
|
5
|
-
import { MongoDBOIDC } from './cmap/auth/mongodb_oidc';
|
|
6
|
+
import { MongoDBOIDC, OIDC_WORKFLOWS, type Workflow } from './cmap/auth/mongodb_oidc';
|
|
7
|
+
import { AutomatedCallbackWorkflow } from './cmap/auth/mongodb_oidc/automated_callback_workflow';
|
|
8
|
+
import { HumanCallbackWorkflow } from './cmap/auth/mongodb_oidc/human_callback_workflow';
|
|
9
|
+
import { TokenCache } from './cmap/auth/mongodb_oidc/token_cache';
|
|
6
10
|
import { Plain } from './cmap/auth/plain';
|
|
7
11
|
import { AuthMechanism } from './cmap/auth/providers';
|
|
8
12
|
import { ScramSHA1, ScramSHA256 } from './cmap/auth/scram';
|
|
@@ -10,11 +14,11 @@ import { X509 } from './cmap/auth/x509';
|
|
|
10
14
|
import { MongoInvalidArgumentError } from './error';
|
|
11
15
|
|
|
12
16
|
/** @internal */
|
|
13
|
-
const AUTH_PROVIDERS = new Map<AuthMechanism | string, () => AuthProvider>([
|
|
17
|
+
const AUTH_PROVIDERS = new Map<AuthMechanism | string, (workflow?: Workflow) => AuthProvider>([
|
|
14
18
|
[AuthMechanism.MONGODB_AWS, () => new MongoDBAWS()],
|
|
15
19
|
[AuthMechanism.MONGODB_CR, () => new MongoCR()],
|
|
16
20
|
[AuthMechanism.MONGODB_GSSAPI, () => new GSSAPI()],
|
|
17
|
-
[AuthMechanism.MONGODB_OIDC, () => new MongoDBOIDC()],
|
|
21
|
+
[AuthMechanism.MONGODB_OIDC, (workflow?: Workflow) => new MongoDBOIDC(workflow)],
|
|
18
22
|
[AuthMechanism.MONGODB_PLAIN, () => new Plain()],
|
|
19
23
|
[AuthMechanism.MONGODB_SCRAM_SHA1, () => new ScramSHA1()],
|
|
20
24
|
[AuthMechanism.MONGODB_SCRAM_SHA256, () => new ScramSHA256()],
|
|
@@ -33,22 +37,56 @@ export class MongoClientAuthProviders {
|
|
|
33
37
|
* Get or create an authentication provider based on the provided mechanism.
|
|
34
38
|
* We don't want to create all providers at once, as some providers may not be used.
|
|
35
39
|
* @param name - The name of the provider to get or create.
|
|
40
|
+
* @param credentials - The credentials.
|
|
36
41
|
* @returns The provider.
|
|
37
42
|
* @throws MongoInvalidArgumentError if the mechanism is not supported.
|
|
38
43
|
* @internal
|
|
39
44
|
*/
|
|
40
|
-
getOrCreateProvider(
|
|
45
|
+
getOrCreateProvider(
|
|
46
|
+
name: AuthMechanism | string,
|
|
47
|
+
authMechanismProperties: AuthMechanismProperties
|
|
48
|
+
): AuthProvider {
|
|
41
49
|
const authProvider = this.existingProviders.get(name);
|
|
42
50
|
if (authProvider) {
|
|
43
51
|
return authProvider;
|
|
44
52
|
}
|
|
45
53
|
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
54
|
+
const providerFunction = AUTH_PROVIDERS.get(name);
|
|
55
|
+
if (!providerFunction) {
|
|
48
56
|
throw new MongoInvalidArgumentError(`authMechanism ${name} not supported`);
|
|
49
57
|
}
|
|
50
58
|
|
|
59
|
+
let provider;
|
|
60
|
+
if (name === AuthMechanism.MONGODB_OIDC) {
|
|
61
|
+
provider = providerFunction(this.getWorkflow(authMechanismProperties));
|
|
62
|
+
} else {
|
|
63
|
+
provider = providerFunction();
|
|
64
|
+
}
|
|
65
|
+
|
|
51
66
|
this.existingProviders.set(name, provider);
|
|
52
67
|
return provider;
|
|
53
68
|
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Gets either a device workflow or callback workflow.
|
|
72
|
+
*/
|
|
73
|
+
getWorkflow(authMechanismProperties: AuthMechanismProperties): Workflow {
|
|
74
|
+
if (authMechanismProperties.OIDC_HUMAN_CALLBACK) {
|
|
75
|
+
return new HumanCallbackWorkflow(
|
|
76
|
+
new TokenCache(),
|
|
77
|
+
authMechanismProperties.OIDC_HUMAN_CALLBACK
|
|
78
|
+
);
|
|
79
|
+
} else if (authMechanismProperties.OIDC_CALLBACK) {
|
|
80
|
+
return new AutomatedCallbackWorkflow(new TokenCache(), authMechanismProperties.OIDC_CALLBACK);
|
|
81
|
+
} else {
|
|
82
|
+
const environment = authMechanismProperties.ENVIRONMENT;
|
|
83
|
+
const workflow = OIDC_WORKFLOWS.get(environment)?.();
|
|
84
|
+
if (!workflow) {
|
|
85
|
+
throw new MongoInvalidArgumentError(
|
|
86
|
+
`Could not load workflow for environment ${authMechanismProperties.ENVIRONMENT}`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return workflow;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
54
92
|
}
|
|
@@ -258,10 +258,19 @@ export function compareTopologyVersion(
|
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
// TODO(NODE-2674): Preserve int64 sent from MongoDB
|
|
261
|
-
const currentCounter =
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
const currentCounter =
|
|
262
|
+
typeof currentTv.counter === 'bigint'
|
|
263
|
+
? Long.fromBigInt(currentTv.counter)
|
|
264
|
+
: Long.isLong(currentTv.counter)
|
|
265
|
+
? currentTv.counter
|
|
266
|
+
: Long.fromNumber(currentTv.counter);
|
|
267
|
+
|
|
268
|
+
const newCounter =
|
|
269
|
+
typeof newTv.counter === 'bigint'
|
|
270
|
+
? Long.fromBigInt(newTv.counter)
|
|
271
|
+
: Long.isLong(newTv.counter)
|
|
272
|
+
? newTv.counter
|
|
273
|
+
: Long.fromNumber(newTv.counter);
|
|
265
274
|
|
|
266
275
|
return currentCounter.compare(newCounter);
|
|
267
276
|
}
|
package/src/sessions.ts
CHANGED
|
@@ -369,6 +369,11 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
|
|
|
369
369
|
/**
|
|
370
370
|
* Starts a new transaction with the given options.
|
|
371
371
|
*
|
|
372
|
+
* @remarks
|
|
373
|
+
* **IMPORTANT**: Running operations in parallel is not supported during a transaction. The use of `Promise.all`,
|
|
374
|
+
* `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is
|
|
375
|
+
* undefined behaviour.
|
|
376
|
+
*
|
|
372
377
|
* @param options - Options for the transaction
|
|
373
378
|
*/
|
|
374
379
|
startTransaction(options?: TransactionOptions): void {
|
|
@@ -443,6 +448,11 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
|
|
|
443
448
|
*
|
|
444
449
|
* **IMPORTANT:** This method requires the function passed in to return a Promise. That promise must be made by `await`-ing all operations in such a way that rejections are propagated to the returned promise.
|
|
445
450
|
*
|
|
451
|
+
* **IMPORTANT:** Running operations in parallel is not supported during a transaction. The use of `Promise.all`,
|
|
452
|
+
* `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is
|
|
453
|
+
* undefined behaviour.
|
|
454
|
+
*
|
|
455
|
+
*
|
|
446
456
|
* @remarks
|
|
447
457
|
* - If all operations successfully complete and the `commitTransaction` operation is successful, then the provided function will return the result of the provided function.
|
|
448
458
|
* - If the transaction is unable to complete or an error is thrown from within the provided function, then the provided function will throw an error.
|
package/src/utils.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { SrvRecord } from 'dns';
|
|
|
3
3
|
import { type EventEmitter } from 'events';
|
|
4
4
|
import { promises as fs } from 'fs';
|
|
5
5
|
import * as http from 'http';
|
|
6
|
+
import { clearTimeout, setTimeout } from 'timers';
|
|
6
7
|
import * as url from 'url';
|
|
7
8
|
import { URL } from 'url';
|
|
8
9
|
import { promisify } from 'util';
|
|
@@ -1157,6 +1158,38 @@ interface RequestOptions {
|
|
|
1157
1158
|
headers?: http.OutgoingHttpHeaders;
|
|
1158
1159
|
}
|
|
1159
1160
|
|
|
1161
|
+
/**
|
|
1162
|
+
* Perform a get request that returns status and body.
|
|
1163
|
+
* @internal
|
|
1164
|
+
*/
|
|
1165
|
+
export function get(
|
|
1166
|
+
url: URL | string,
|
|
1167
|
+
options: http.RequestOptions = {}
|
|
1168
|
+
): Promise<{ body: string; status: number | undefined }> {
|
|
1169
|
+
return new Promise((resolve, reject) => {
|
|
1170
|
+
/* eslint-disable prefer-const */
|
|
1171
|
+
let timeoutId: NodeJS.Timeout;
|
|
1172
|
+
const request = http
|
|
1173
|
+
.get(url, options, response => {
|
|
1174
|
+
response.setEncoding('utf8');
|
|
1175
|
+
let body = '';
|
|
1176
|
+
response.on('data', chunk => (body += chunk));
|
|
1177
|
+
response.on('end', () => {
|
|
1178
|
+
clearTimeout(timeoutId);
|
|
1179
|
+
resolve({ status: response.statusCode, body });
|
|
1180
|
+
});
|
|
1181
|
+
})
|
|
1182
|
+
.on('error', error => {
|
|
1183
|
+
clearTimeout(timeoutId);
|
|
1184
|
+
reject(error);
|
|
1185
|
+
})
|
|
1186
|
+
.end();
|
|
1187
|
+
timeoutId = setTimeout(() => {
|
|
1188
|
+
request.destroy(new MongoNetworkTimeoutError(`request timed out after 10 seconds`));
|
|
1189
|
+
}, 10000);
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1160
1193
|
export async function request(uri: string): Promise<Record<string, any>>;
|
|
1161
1194
|
export async function request(
|
|
1162
1195
|
uri: string,
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.get = void 0;
|
|
4
|
-
const http = require("http");
|
|
5
|
-
const timers_1 = require("timers");
|
|
6
|
-
const errors_1 = require("../errors");
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
function get(url, options = {}) {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
/* eslint-disable prefer-const */
|
|
13
|
-
let timeoutId;
|
|
14
|
-
const request = http
|
|
15
|
-
.get(url, options, response => {
|
|
16
|
-
response.setEncoding('utf8');
|
|
17
|
-
let body = '';
|
|
18
|
-
response.on('data', chunk => (body += chunk));
|
|
19
|
-
response.on('end', () => {
|
|
20
|
-
(0, timers_1.clearTimeout)(timeoutId);
|
|
21
|
-
resolve({ status: response.statusCode, body });
|
|
22
|
-
});
|
|
23
|
-
})
|
|
24
|
-
.on('error', error => {
|
|
25
|
-
(0, timers_1.clearTimeout)(timeoutId);
|
|
26
|
-
reject(error);
|
|
27
|
-
})
|
|
28
|
-
.end();
|
|
29
|
-
timeoutId = (0, timers_1.setTimeout)(() => {
|
|
30
|
-
request.destroy(new errors_1.MongoCryptKMSRequestNetworkTimeoutError(`request timed out after 10 seconds`));
|
|
31
|
-
}, 10000);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
exports.get = get;
|
|
35
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/client-side-encryption/providers/utils.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,mCAAkD;AAElD,sCAAoE;AAEpE;;GAEG;AACH,SAAgB,GAAG,CACjB,GAAiB,EACjB,UAA+B,EAAE;IAEjC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,iCAAiC;QACjC,IAAI,SAAyB,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAI;aACjB,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE;YAC5B,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YAC7B,IAAI,IAAI,GAAG,EAAE,CAAC;YACd,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC;YAC9C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBACtB,IAAA,qBAAY,EAAC,SAAS,CAAC,CAAC;gBACxB,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;aACD,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE;YACnB,IAAA,qBAAY,EAAC,SAAS,CAAC,CAAC;YACxB,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC;aACD,GAAG,EAAE,CAAC;QACT,SAAS,GAAG,IAAA,mBAAU,EAAC,GAAG,EAAE;YAC1B,OAAO,CAAC,OAAO,CACb,IAAI,gDAAuC,CAAC,oCAAoC,CAAC,CAClF,CAAC;QACJ,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC;AA5BD,kBA4BC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AwsServiceWorkflow = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const error_1 = require("../../../error");
|
|
6
|
-
const service_workflow_1 = require("./service_workflow");
|
|
7
|
-
/** Error for when the token is missing in the environment. */
|
|
8
|
-
const TOKEN_MISSING_ERROR = 'AWS_WEB_IDENTITY_TOKEN_FILE must be set in the environment.';
|
|
9
|
-
/**
|
|
10
|
-
* Device workflow implementation for AWS.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
class AwsServiceWorkflow extends service_workflow_1.ServiceWorkflow {
|
|
15
|
-
constructor() {
|
|
16
|
-
super();
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Get the token from the environment.
|
|
20
|
-
*/
|
|
21
|
-
async getToken() {
|
|
22
|
-
const tokenFile = process.env.AWS_WEB_IDENTITY_TOKEN_FILE;
|
|
23
|
-
if (!tokenFile) {
|
|
24
|
-
throw new error_1.MongoAWSError(TOKEN_MISSING_ERROR);
|
|
25
|
-
}
|
|
26
|
-
return await fs.promises.readFile(tokenFile, 'utf8');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.AwsServiceWorkflow = AwsServiceWorkflow;
|
|
30
|
-
//# sourceMappingURL=aws_service_workflow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aws_service_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/aws_service_workflow.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AAEzB,0CAA+C;AAC/C,yDAAqD;AAErD,8DAA8D;AAC9D,MAAM,mBAAmB,GAAG,6DAA6D,CAAC;AAE1F;;;;GAIG;AACH,MAAa,kBAAmB,SAAQ,kCAAe;IACrD;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;QAC1D,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,qBAAa,CAAC,mBAAmB,CAAC,CAAC;SAC9C;QACD,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACvD,CAAC;CACF;AAfD,gDAeC"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AzureServiceWorkflow = void 0;
|
|
4
|
-
const error_1 = require("../../../error");
|
|
5
|
-
const utils_1 = require("../../../utils");
|
|
6
|
-
const azure_token_cache_1 = require("./azure_token_cache");
|
|
7
|
-
const service_workflow_1 = require("./service_workflow");
|
|
8
|
-
/** Base URL for getting Azure tokens. */
|
|
9
|
-
const AZURE_BASE_URL = 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01';
|
|
10
|
-
/** Azure request headers. */
|
|
11
|
-
const AZURE_HEADERS = Object.freeze({ Metadata: 'true', Accept: 'application/json' });
|
|
12
|
-
/** Invalid endpoint result error. */
|
|
13
|
-
const ENDPOINT_RESULT_ERROR = 'Azure endpoint did not return a value with only access_token and expires_in properties';
|
|
14
|
-
/** Error for when the token audience is missing in the environment. */
|
|
15
|
-
const TOKEN_AUDIENCE_MISSING_ERROR = 'TOKEN_AUDIENCE must be set in the auth mechanism properties when PROVIDER_NAME is azure.';
|
|
16
|
-
/**
|
|
17
|
-
* Device workflow implementation for Azure.
|
|
18
|
-
*
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
class AzureServiceWorkflow extends service_workflow_1.ServiceWorkflow {
|
|
22
|
-
constructor() {
|
|
23
|
-
super(...arguments);
|
|
24
|
-
this.cache = new azure_token_cache_1.AzureTokenCache();
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Get the token from the environment.
|
|
28
|
-
*/
|
|
29
|
-
async getToken(credentials) {
|
|
30
|
-
const tokenAudience = credentials?.mechanismProperties.TOKEN_AUDIENCE;
|
|
31
|
-
if (!tokenAudience) {
|
|
32
|
-
throw new error_1.MongoAzureError(TOKEN_AUDIENCE_MISSING_ERROR);
|
|
33
|
-
}
|
|
34
|
-
let token;
|
|
35
|
-
const entry = this.cache.getEntry(tokenAudience);
|
|
36
|
-
if (entry?.isValid()) {
|
|
37
|
-
token = entry.token;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this.cache.deleteEntry(tokenAudience);
|
|
41
|
-
const response = await getAzureTokenData(tokenAudience);
|
|
42
|
-
if (!isEndpointResultValid(response)) {
|
|
43
|
-
throw new error_1.MongoAzureError(ENDPOINT_RESULT_ERROR);
|
|
44
|
-
}
|
|
45
|
-
this.cache.addEntry(tokenAudience, response);
|
|
46
|
-
token = response.access_token;
|
|
47
|
-
}
|
|
48
|
-
return token;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.AzureServiceWorkflow = AzureServiceWorkflow;
|
|
52
|
-
/**
|
|
53
|
-
* Hit the Azure endpoint to get the token data.
|
|
54
|
-
*/
|
|
55
|
-
async function getAzureTokenData(tokenAudience) {
|
|
56
|
-
const url = `${AZURE_BASE_URL}&resource=${tokenAudience}`;
|
|
57
|
-
const data = await (0, utils_1.request)(url, {
|
|
58
|
-
json: true,
|
|
59
|
-
headers: AZURE_HEADERS
|
|
60
|
-
});
|
|
61
|
-
return data;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Determines if a result returned from the endpoint is valid.
|
|
65
|
-
* This means the result is not nullish, contains the access_token required field
|
|
66
|
-
* and the expires_in required field.
|
|
67
|
-
*/
|
|
68
|
-
function isEndpointResultValid(token) {
|
|
69
|
-
if (token == null || typeof token !== 'object')
|
|
70
|
-
return false;
|
|
71
|
-
return 'access_token' in token && 'expires_in' in token;
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=azure_service_workflow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"azure_service_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/azure_service_workflow.ts"],"names":[],"mappings":";;;AAAA,0CAAiD;AACjD,0CAAyC;AAEzC,2DAAsD;AACtD,yDAAqD;AAErD,yCAAyC;AACzC,MAAM,cAAc,GAClB,8EAA8E,CAAC;AAEjF,6BAA6B;AAC7B,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAEtF,qCAAqC;AACrC,MAAM,qBAAqB,GACzB,wFAAwF,CAAC;AAE3F,uEAAuE;AACvE,MAAM,4BAA4B,GAChC,0FAA0F,CAAC;AAW7F;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,kCAAe;IAAzD;;QACE,UAAK,GAAG,IAAI,mCAAe,EAAE,CAAC;IAyBhC,CAAC;IAvBC;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,WAA8B;QAC3C,MAAM,aAAa,GAAG,WAAW,EAAE,mBAAmB,CAAC,cAAc,CAAC;QACtE,IAAI,CAAC,aAAa,EAA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", { value: true });
|
|
3
|
-
exports.AzureTokenCache = exports.AzureTokenEntry = void 0;
|
|
4
|
-
const cache_1 = require("./cache");
|
|
5
|
-
/** @internal */
|
|
6
|
-
class AzureTokenEntry extends cache_1.ExpiringCacheEntry {
|
|
7
|
-
/**
|
|
8
|
-
* Instantiate the entry.
|
|
9
|
-
*/
|
|
10
|
-
constructor(token, expiration) {
|
|
11
|
-
super(expiration);
|
|
12
|
-
this.token = token;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.AzureTokenEntry = AzureTokenEntry;
|
|
16
|
-
/**
|
|
17
|
-
* A cache of access tokens from Azure.
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
class AzureTokenCache extends cache_1.Cache {
|
|
21
|
-
/**
|
|
22
|
-
* Add an entry to the cache.
|
|
23
|
-
*/
|
|
24
|
-
addEntry(tokenAudience, token) {
|
|
25
|
-
const entry = new AzureTokenEntry(token.access_token, token.expires_in);
|
|
26
|
-
this.entries.set(tokenAudience, entry);
|
|
27
|
-
return entry;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Create a cache key.
|
|
31
|
-
*/
|
|
32
|
-
cacheKey(tokenAudience) {
|
|
33
|
-
return tokenAudience;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Delete an entry from the cache.
|
|
37
|
-
*/
|
|
38
|
-
deleteEntry(tokenAudience) {
|
|
39
|
-
this.entries.delete(tokenAudience);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Get an Azure token entry from the cache.
|
|
43
|
-
*/
|
|
44
|
-
getEntry(tokenAudience) {
|
|
45
|
-
return this.entries.get(tokenAudience);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.AzureTokenCache = AzureTokenCache;
|
|
49
|
-
//# sourceMappingURL=azure_token_cache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"azure_token_cache.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/azure_token_cache.ts"],"names":[],"mappings":";;;AACA,mCAAoD;AAEpD,gBAAgB;AAChB,MAAa,eAAgB,SAAQ,0BAAkB;IAGrD;;OAEG;IACH,YAAY,KAAa,EAAE,UAAkB;QAC3C,KAAK,CAAC,UAAU,CAAC,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAVD,0CAUC;AAED;;;GAGG;AACH,MAAa,eAAgB,SAAQ,aAAsB;IACzD;;OAEG;IACH,QAAQ,CAAC,aAAqB,EAAE,KAAuB;QACrD,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QACxE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,aAAqB;QAC5B,OAAO,aAAa,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,aAAqB;QAC/B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,aAAqB;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACzC,CAAC;CACF;AA9BD,0CA8BC"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Cache = exports.ExpiringCacheEntry = void 0;
|
|
4
|
-
/* 5 minutes in milliseconds */
|
|
5
|
-
const EXPIRATION_BUFFER_MS = 300000;
|
|
6
|
-
/**
|
|
7
|
-
* An entry in a cache that can expire in a certain amount of time.
|
|
8
|
-
*/
|
|
9
|
-
class ExpiringCacheEntry {
|
|
10
|
-
/**
|
|
11
|
-
* Create a new expiring token entry.
|
|
12
|
-
*/
|
|
13
|
-
constructor(expiration) {
|
|
14
|
-
this.expiration = this.expirationTime(expiration);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* The entry is still valid if the expiration is more than
|
|
18
|
-
* 5 minutes from the expiration time.
|
|
19
|
-
*/
|
|
20
|
-
isValid() {
|
|
21
|
-
return this.expiration - Date.now() > EXPIRATION_BUFFER_MS;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Get an expiration time in milliseconds past epoch.
|
|
25
|
-
*/
|
|
26
|
-
expirationTime(expiresInSeconds) {
|
|
27
|
-
return Date.now() + expiresInSeconds * 1000;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.ExpiringCacheEntry = ExpiringCacheEntry;
|
|
31
|
-
/**
|
|
32
|
-
* Base class for OIDC caches.
|
|
33
|
-
*/
|
|
34
|
-
class Cache {
|
|
35
|
-
/**
|
|
36
|
-
* Create a new cache.
|
|
37
|
-
*/
|
|
38
|
-
constructor() {
|
|
39
|
-
this.entries = new Map();
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Clear the cache.
|
|
43
|
-
*/
|
|
44
|
-
clear() {
|
|
45
|
-
this.entries.clear();
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Create a cache key from the address and username.
|
|
49
|
-
*/
|
|
50
|
-
hashedCacheKey(address, username, callbackHash) {
|
|
51
|
-
return JSON.stringify([address, username, callbackHash]);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.Cache = Cache;
|
|
55
|
-
//# sourceMappingURL=cache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/cache.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAEpC;;GAEG;AACH,MAAsB,kBAAkB;IAGtC;;OAEG;IACH,YAAY,UAAkB;QAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC;IACD;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,oBAAoB,CAAC;IAC7D,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,gBAAwB;QAC7C,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAC9C,CAAC;CACF;AAvBD,gDAuBC;AAED;;GAEG;AACH,MAAsB,KAAK;IAGzB;;OAEG;IACH;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAa,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAOD;;OAEG;IACH,cAAc,CAAC,OAAe,EAAE,QAAgB,EAAE,YAAoB;QACpE,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AA5BD,sBA4BC"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CallbackLockCache = void 0;
|
|
4
|
-
const error_1 = require("../../../error");
|
|
5
|
-
const cache_1 = require("./cache");
|
|
6
|
-
/** Error message for when request callback is missing. */
|
|
7
|
-
const REQUEST_CALLBACK_REQUIRED_ERROR = 'Auth mechanism property REQUEST_TOKEN_CALLBACK is required.';
|
|
8
|
-
/* Counter for function "hashes".*/
|
|
9
|
-
let FN_HASH_COUNTER = 0;
|
|
10
|
-
/* No function present function */
|
|
11
|
-
const NO_FUNCTION = async () => ({ accessToken: 'test' });
|
|
12
|
-
/* The map of function hashes */
|
|
13
|
-
const FN_HASHES = new WeakMap();
|
|
14
|
-
/* Put the no function hash in the map. */
|
|
15
|
-
FN_HASHES.set(NO_FUNCTION, FN_HASH_COUNTER);
|
|
16
|
-
/**
|
|
17
|
-
* A cache of request and refresh callbacks per server/user.
|
|
18
|
-
*/
|
|
19
|
-
class CallbackLockCache extends cache_1.Cache {
|
|
20
|
-
/**
|
|
21
|
-
* Get the callbacks for the connection and credentials. If an entry does not
|
|
22
|
-
* exist a new one will get set.
|
|
23
|
-
*/
|
|
24
|
-
getEntry(connection, credentials) {
|
|
25
|
-
const requestCallback = credentials.mechanismProperties.REQUEST_TOKEN_CALLBACK;
|
|
26
|
-
const refreshCallback = credentials.mechanismProperties.REFRESH_TOKEN_CALLBACK;
|
|
27
|
-
if (!requestCallback) {
|
|
28
|
-
throw new error_1.MongoInvalidArgumentError(REQUEST_CALLBACK_REQUIRED_ERROR);
|
|
29
|
-
}
|
|
30
|
-
const callbackHash = hashFunctions(requestCallback, refreshCallback);
|
|
31
|
-
const key = this.cacheKey(connection.address, credentials.username, callbackHash);
|
|
32
|
-
const entry = this.entries.get(key);
|
|
33
|
-
if (entry) {
|
|
34
|
-
return entry;
|
|
35
|
-
}
|
|
36
|
-
return this.addEntry(key, callbackHash, requestCallback, refreshCallback);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Set locked callbacks on for connection and credentials.
|
|
40
|
-
*/
|
|
41
|
-
addEntry(key, callbackHash, requestCallback, refreshCallback) {
|
|
42
|
-
const entry = {
|
|
43
|
-
requestCallback: withLock(requestCallback),
|
|
44
|
-
refreshCallback: refreshCallback ? withLock(refreshCallback) : undefined,
|
|
45
|
-
callbackHash: callbackHash
|
|
46
|
-
};
|
|
47
|
-
this.entries.set(key, entry);
|
|
48
|
-
return entry;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Create a cache key from the address and username.
|
|
52
|
-
*/
|
|
53
|
-
cacheKey(address, username, callbackHash) {
|
|
54
|
-
return this.hashedCacheKey(address, username, callbackHash);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.CallbackLockCache = CallbackLockCache;
|
|
58
|
-
/**
|
|
59
|
-
* Ensure the callback is only executed one at a time.
|
|
60
|
-
*/
|
|
61
|
-
function withLock(callback) {
|
|
62
|
-
let lock = Promise.resolve();
|
|
63
|
-
return async (info, context) => {
|
|
64
|
-
await lock;
|
|
65
|
-
// eslint-disable-next-line github/no-then
|
|
66
|
-
lock = lock.then(() => callback(info, context));
|
|
67
|
-
return await lock;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get the hash string for the request and refresh functions.
|
|
72
|
-
*/
|
|
73
|
-
function hashFunctions(requestFn, refreshFn) {
|
|
74
|
-
let requestHash = FN_HASHES.get(requestFn);
|
|
75
|
-
let refreshHash = FN_HASHES.get(refreshFn ?? NO_FUNCTION);
|
|
76
|
-
if (requestHash == null) {
|
|
77
|
-
// Create a new one for the function and put it in the map.
|
|
78
|
-
FN_HASH_COUNTER++;
|
|
79
|
-
requestHash = FN_HASH_COUNTER;
|
|
80
|
-
FN_HASHES.set(requestFn, FN_HASH_COUNTER);
|
|
81
|
-
}
|
|
82
|
-
if (refreshHash == null && refreshFn) {
|
|
83
|
-
// Create a new one for the function and put it in the map.
|
|
84
|
-
FN_HASH_COUNTER++;
|
|
85
|
-
refreshHash = FN_HASH_COUNTER;
|
|
86
|
-
FN_HASHES.set(refreshFn, FN_HASH_COUNTER);
|
|
87
|
-
}
|
|
88
|
-
return `${requestHash}-${refreshHash}`;
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=callback_lock_cache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"callback_lock_cache.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/callback_lock_cache.ts"],"names":[],"mappings":";;;AAAA,0CAA2D;AAU3D,mCAAgC;AAEhC,0DAA0D;AAC1D,MAAM,+BAA+B,GACnC,6DAA6D,CAAC;AAChE,mCAAmC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GAAG,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;KAC3C;IACD,OAAO,GAAG,WAAW,IAAI,WAAW,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.commandDocument = exports.ServiceWorkflow = void 0;
|
|
4
|
-
const bson_1 = require("bson");
|
|
5
|
-
const utils_1 = require("../../../utils");
|
|
6
|
-
const providers_1 = require("../providers");
|
|
7
|
-
/**
|
|
8
|
-
* Common behaviour for OIDC device workflows.
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
class ServiceWorkflow {
|
|
12
|
-
/**
|
|
13
|
-
* Execute the workflow. Looks for AWS_WEB_IDENTITY_TOKEN_FILE in the environment
|
|
14
|
-
* and then attempts to read the token from that path.
|
|
15
|
-
*/
|
|
16
|
-
async execute(connection, credentials) {
|
|
17
|
-
const token = await this.getToken(credentials);
|
|
18
|
-
const command = commandDocument(token);
|
|
19
|
-
return await connection.command((0, utils_1.ns)(credentials.source), command, undefined);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Get the document to add for speculative authentication.
|
|
23
|
-
*/
|
|
24
|
-
async speculativeAuth(credentials) {
|
|
25
|
-
const token = await this.getToken(credentials);
|
|
26
|
-
const document = commandDocument(token);
|
|
27
|
-
document.db = credentials.source;
|
|
28
|
-
return { speculativeAuthenticate: document };
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.ServiceWorkflow = ServiceWorkflow;
|
|
32
|
-
/**
|
|
33
|
-
* Create the saslStart command document.
|
|
34
|
-
*/
|
|
35
|
-
function commandDocument(token) {
|
|
36
|
-
return {
|
|
37
|
-
saslStart: 1,
|
|
38
|
-
mechanism: providers_1.AuthMechanism.MONGODB_OIDC,
|
|
39
|
-
payload: bson_1.BSON.serialize({ jwt: token })
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
exports.commandDocument = commandDocument;
|
|
43
|
-
//# sourceMappingURL=service_workflow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/service_workflow.ts"],"names":[],"mappings":";;;AAAA,+BAA2C;AAE3C,0CAAoC;AAIpC,4CAA6C;AAE7C;;;GAGG;AACH,MAAsB,eAAe;IACnC;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,UAAsB,EAAE,WAA6B;QACjE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC/C,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACvC,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC,IAAA,UAAE,EAAC,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAC9E,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,WAA6B;QACjD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC/C,MAAM,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACxC,QAAQ,CAAC,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC;QACjC,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,CAAC;IAC/C,CAAC;CAMF;AAzBD,0CAyBC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAa;IAC3C,OAAO;QACL,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,yBAAa,CAAC,YAAY;QACrC,OAAO,EAAE,WAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;KACxC,CAAC;AACJ,CAAC;AAND,0CAMC"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TokenEntryCache = exports.TokenEntry = void 0;
|
|
4
|
-
const cache_1 = require("./cache");
|
|
5
|
-
/* Default expiration is now for when no expiration provided */
|
|
6
|
-
const DEFAULT_EXPIRATION_SECS = 0;
|
|
7
|
-
/** @internal */
|
|
8
|
-
class TokenEntry extends cache_1.ExpiringCacheEntry {
|
|
9
|
-
/**
|
|
10
|
-
* Instantiate the entry.
|
|
11
|
-
*/
|
|
12
|
-
constructor(tokenResult, serverInfo, expiration) {
|
|
13
|
-
super(expiration);
|
|
14
|
-
this.tokenResult = tokenResult;
|
|
15
|
-
this.serverInfo = serverInfo;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.TokenEntry = TokenEntry;
|
|
19
|
-
/**
|
|
20
|
-
* Cache of OIDC token entries.
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
class TokenEntryCache extends cache_1.Cache {
|
|
24
|
-
/**
|
|
25
|
-
* Set an entry in the token cache.
|
|
26
|
-
*/
|
|
27
|
-
addEntry(address, username, callbackHash, tokenResult, serverInfo) {
|
|
28
|
-
const entry = new TokenEntry(tokenResult, serverInfo, tokenResult.expiresInSeconds ?? DEFAULT_EXPIRATION_SECS);
|
|
29
|
-
this.entries.set(this.cacheKey(address, username, callbackHash), entry);
|
|
30
|
-
return entry;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Delete an entry from the cache.
|
|
34
|
-
*/
|
|
35
|
-
deleteEntry(address, username, callbackHash) {
|
|
36
|
-
this.entries.delete(this.cacheKey(address, username, callbackHash));
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Get an entry from the cache.
|
|
40
|
-
*/
|
|
41
|
-
getEntry(address, username, callbackHash) {
|
|
42
|
-
return this.entries.get(this.cacheKey(address, username, callbackHash));
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Delete all expired entries from the cache.
|
|
46
|
-
*/
|
|
47
|
-
deleteExpiredEntries() {
|
|
48
|
-
for (const [key, entry] of this.entries) {
|
|
49
|
-
if (!entry.isValid()) {
|
|
50
|
-
this.entries.delete(key);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Create a cache key from the address and username.
|
|
56
|
-
*/
|
|
57
|
-
cacheKey(address, username, callbackHash) {
|
|
58
|
-
return this.hashedCacheKey(address, username, callbackHash);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.TokenEntryCache = TokenEntryCache;
|
|
62
|
-
//# sourceMappingURL=token_entry_cache.js.map
|