mongodb 6.6.2 → 6.7.0-dev.20240607.sha.aa429f8c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- 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 +140 -36
- package/package.json +7 -6
- package/src/client-side-encryption/client_encryption.ts +27 -13
- 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 +9 -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callback_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/callback_workflow.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"callback_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/callback_workflow.ts"],"names":[],"mappings":";;;AACA,8CAA6C;AAE7C,0CAA8D;AAC9D,0CAAoC;AASpC,yDAAiF;AAGjF,gCAAgC;AACnB,QAAA,gBAAgB,GAAG,MAAM,CAAC;AACvC,+BAA+B;AAClB,QAAA,oBAAoB,GAAG,KAAK,CAAC;AAE1C,kDAAkD;AAClD,MAAM,iBAAiB,GAAG,CAAC,aAAa,EAAE,kBAAkB,EAAE,cAAc,CAAC,CAAC;AAE9E,yDAAyD;AACzD,MAAM,qBAAqB,GACzB,8EAA8E,CAAC;AAEjF,2CAA2C;AAC3C,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB;;;GAGG;AACH,MAAsB,gBAAgB;IAKpC;;OAEG;IACH,YAAY,KAAiB,EAAE,QAA8B;QAC3D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC;IACpD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe,CAAC,UAAsB,EAAE,WAA6B;QACzE,iDAAiD;QACjD,uFAAuF;QACvF,+EAA+E;QAC/E,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;YAC7B,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;YAChD,UAAU,CAAC,WAAW,GAAG,WAAW,CAAC;YACrC,MAAM,QAAQ,GAAG,IAAA,wCAAqB,EAAC,WAAW,CAAC,CAAC;YACpD,QAAQ,CAAC,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC;YACjC,OAAO,EAAE,uBAAuB,EAAE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IAAI,CAAC;IACxE,IAAI,CAAC,CAAC,aAAa,IAAI,WAAW,CAAC;QAAE,OAAO,IAAI,CAAC;IACjD,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startCommandDocument = exports.finishCommandDocument = void 0;
|
|
4
|
+
const bson_1 = require("bson");
|
|
5
|
+
const providers_1 = require("../providers");
|
|
6
|
+
/**
|
|
7
|
+
* Generate the finishing command document for authentication. Will be a
|
|
8
|
+
* saslStart or saslContinue depending on the presence of a conversation id.
|
|
9
|
+
*/
|
|
10
|
+
function finishCommandDocument(token, conversationId) {
|
|
11
|
+
if (conversationId != null) {
|
|
12
|
+
return {
|
|
13
|
+
saslContinue: 1,
|
|
14
|
+
conversationId: conversationId,
|
|
15
|
+
payload: new bson_1.Binary(bson_1.BSON.serialize({ jwt: token }))
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
// saslContinue requires a conversationId in the command to be valid so in this
|
|
19
|
+
// case the server allows "step two" to actually be a saslStart with the token
|
|
20
|
+
// as the jwt since the use of the cached value has no correlating conversating
|
|
21
|
+
// on the particular connection.
|
|
22
|
+
return {
|
|
23
|
+
saslStart: 1,
|
|
24
|
+
mechanism: providers_1.AuthMechanism.MONGODB_OIDC,
|
|
25
|
+
payload: new bson_1.Binary(bson_1.BSON.serialize({ jwt: token }))
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.finishCommandDocument = finishCommandDocument;
|
|
29
|
+
/**
|
|
30
|
+
* Generate the saslStart command document.
|
|
31
|
+
*/
|
|
32
|
+
function startCommandDocument(credentials) {
|
|
33
|
+
const payload = {};
|
|
34
|
+
if (credentials.username) {
|
|
35
|
+
payload.n = credentials.username;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
saslStart: 1,
|
|
39
|
+
autoAuthorize: 1,
|
|
40
|
+
mechanism: providers_1.AuthMechanism.MONGODB_OIDC,
|
|
41
|
+
payload: new bson_1.Binary(bson_1.BSON.serialize(payload))
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.startCommandDocument = startCommandDocument;
|
|
45
|
+
//# sourceMappingURL=command_builders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command_builders.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/command_builders.ts"],"names":[],"mappings":";;;AAAA,+BAAmD;AAGnD,4CAA6C;AAa7C;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,KAAa,EAAE,cAAuB;IAC1E,IAAI,cAAc,IAAI,IAAI,EAAE;QAC1B,OAAO;YACL,YAAY,EAAE,CAAC;YACf,cAAc,EAAE,cAAc;YAC9B,OAAO,EAAE,IAAI,aAAM,CAAC,WAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;SACpD,CAAC;KACH;IACD,+EAA+E;IAC/E,8EAA8E;IAC9E,+EAA+E;IAC/E,gCAAgC;IAChC,OAAO;QACL,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,yBAAa,CAAC,YAAY;QACrC,OAAO,EAAE,IAAI,aAAM,CAAC,WAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;KACpD,CAAC;AACJ,CAAC;AAjBD,sDAiBC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,WAA6B;IAChE,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,WAAW,CAAC,QAAQ,EAAE;QACxB,OAAO,CAAC,CAAC,GAAG,WAAW,CAAC,QAAQ,CAAC;KAClC;IACD,OAAO;QACL,SAAS,EAAE,CAAC;QACZ,aAAa,EAAE,CAAC;QAChB,SAAS,EAAE,yBAAa,CAAC,YAAY;QACrC,OAAO,EAAE,IAAI,aAAM,CAAC,WAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;KAC7C,CAAC;AACJ,CAAC;AAXD,oDAWC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GCPMachineWorkflow = void 0;
|
|
4
|
+
const error_1 = require("../../../error");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
const machine_workflow_1 = require("./machine_workflow");
|
|
7
|
+
/** GCP base URL. */
|
|
8
|
+
const GCP_BASE_URL = 'http://metadata/computeMetadata/v1/instance/service-accounts/default/identity';
|
|
9
|
+
/** GCP request headers. */
|
|
10
|
+
const GCP_HEADERS = Object.freeze({ 'Metadata-Flavor': 'Google' });
|
|
11
|
+
/** Error for when the token audience is missing in the environment. */
|
|
12
|
+
const TOKEN_RESOURCE_MISSING_ERROR = 'TOKEN_RESOURCE must be set in the auth mechanism properties when ENVIRONMENT is gcp.';
|
|
13
|
+
class GCPMachineWorkflow extends machine_workflow_1.MachineWorkflow {
|
|
14
|
+
/**
|
|
15
|
+
* Instantiate the machine workflow.
|
|
16
|
+
*/
|
|
17
|
+
constructor(cache) {
|
|
18
|
+
super(cache);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get the token from the environment.
|
|
22
|
+
*/
|
|
23
|
+
async getToken(credentials) {
|
|
24
|
+
const tokenAudience = credentials?.mechanismProperties.TOKEN_RESOURCE;
|
|
25
|
+
if (!tokenAudience) {
|
|
26
|
+
throw new error_1.MongoGCPError(TOKEN_RESOURCE_MISSING_ERROR);
|
|
27
|
+
}
|
|
28
|
+
return await getGcpTokenData(tokenAudience);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.GCPMachineWorkflow = GCPMachineWorkflow;
|
|
32
|
+
/**
|
|
33
|
+
* Hit the GCP endpoint to get the token data.
|
|
34
|
+
*/
|
|
35
|
+
async function getGcpTokenData(tokenAudience) {
|
|
36
|
+
const url = new URL(GCP_BASE_URL);
|
|
37
|
+
url.searchParams.append('audience', tokenAudience);
|
|
38
|
+
const response = await (0, utils_1.get)(url, {
|
|
39
|
+
headers: GCP_HEADERS
|
|
40
|
+
});
|
|
41
|
+
if (response.status !== 200) {
|
|
42
|
+
throw new error_1.MongoGCPError(`Status code ${response.status} returned from the GCP endpoint. Response body: ${response.body}`);
|
|
43
|
+
}
|
|
44
|
+
return { access_token: response.body };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=gcp_machine_workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gcp_machine_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts"],"names":[],"mappings":";;;AAAA,0CAA+C;AAC/C,0CAAqC;AAErC,yDAAuE;AAGvE,oBAAoB;AACpB,MAAM,YAAY,GAChB,+EAA+E,CAAC;AAElF,2BAA2B;AAC3B,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,iBAAiB,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEnE,uEAAuE;AACvE,MAAM,4BAA4B,GAChC,sFAAsF,CAAC;AAEzF,MAAa,kBAAmB,SAAQ,kCAAe;IACrD;;OAEG;IACH,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,WAA8B;QAC3C,MAAM,aAAa,GAAG,WAAW,EAAE,mBAAmB,CAAC,cAAc,CAAC;QACtE,IAAI,CAAC,aAAa,EAAE;YAClB,MAAM,IAAI,qBAAa,CAAC,4BAA4B,CAAC,CAAC;SACvD;QACD,OAAO,MAAM,eAAe,CAAC,aAAa,CAAC,CAAC;IAC9C,CAAC;CACF;AAlBD,gDAkBC;AAED;;GAEG;AACH,KAAK,UAAU,eAAe,CAAC,aAAqB;IAClD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAClC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,MAAM,IAAA,WAAG,EAAC,GAAG,EAAE;QAC9B,OAAO,EAAE,WAAW;KACrB,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;QAC3B,MAAM,IAAI,qBAAa,CACrB,eAAe,QAAQ,CAAC,MAAM,mDAAmD,QAAQ,CAAC,IAAI,EAAE,CACjG,CAAC;KACH;IACD,OAAO,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HumanCallbackWorkflow = void 0;
|
|
4
|
+
const bson_1 = require("bson");
|
|
5
|
+
const error_1 = require("../../../error");
|
|
6
|
+
const timeout_1 = require("../../../timeout");
|
|
7
|
+
const mongodb_oidc_1 = require("../mongodb_oidc");
|
|
8
|
+
const callback_workflow_1 = require("./callback_workflow");
|
|
9
|
+
/**
|
|
10
|
+
* Class implementing behaviour for the non human callback workflow.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
class HumanCallbackWorkflow extends callback_workflow_1.CallbackWorkflow {
|
|
14
|
+
/**
|
|
15
|
+
* Instantiate the human callback workflow.
|
|
16
|
+
*/
|
|
17
|
+
constructor(cache, callback) {
|
|
18
|
+
super(cache, callback);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Execute the OIDC human callback workflow.
|
|
22
|
+
*/
|
|
23
|
+
async execute(connection, credentials) {
|
|
24
|
+
// Check if the Client Cache has an access token.
|
|
25
|
+
// If it does, cache the access token in the Connection Cache and perform a One-Step SASL conversation
|
|
26
|
+
// using the access token. If the server returns an Authentication error (18),
|
|
27
|
+
// invalidate the access token token from the Client Cache, clear the Connection Cache,
|
|
28
|
+
// and restart the authentication flow. Raise any other errors to the user. On success, exit the algorithm.
|
|
29
|
+
if (this.cache.hasAccessToken) {
|
|
30
|
+
const token = this.cache.getAccessToken();
|
|
31
|
+
connection.accessToken = token;
|
|
32
|
+
try {
|
|
33
|
+
return await this.finishAuthentication(connection, credentials, token);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error instanceof error_1.MongoError &&
|
|
37
|
+
error.code === error_1.MONGODB_ERROR_CODES.AuthenticationFailed) {
|
|
38
|
+
this.cache.removeAccessToken();
|
|
39
|
+
delete connection.accessToken;
|
|
40
|
+
return await this.execute(connection, credentials);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Check if the Client Cache has a refresh token.
|
|
48
|
+
// If it does, call the OIDC Human Callback with the cached refresh token and IdpInfo to get a
|
|
49
|
+
// new access token. Cache the new access token in the Client Cache and Connection Cache.
|
|
50
|
+
// Perform a One-Step SASL conversation using the new access token. If the the server returns
|
|
51
|
+
// an Authentication error (18), clear the refresh token, invalidate the access token from the
|
|
52
|
+
// Client Cache, clear the Connection Cache, and restart the authentication flow. Raise any other
|
|
53
|
+
// errors to the user. On success, exit the algorithm.
|
|
54
|
+
if (this.cache.hasRefreshToken) {
|
|
55
|
+
const refreshToken = this.cache.getRefreshToken();
|
|
56
|
+
const result = await this.fetchAccessToken(this.cache.getIdpInfo(), credentials, refreshToken);
|
|
57
|
+
this.cache.put(result);
|
|
58
|
+
connection.accessToken = result.accessToken;
|
|
59
|
+
try {
|
|
60
|
+
return await this.finishAuthentication(connection, credentials, result.accessToken);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error instanceof error_1.MongoError &&
|
|
64
|
+
error.code === error_1.MONGODB_ERROR_CODES.AuthenticationFailed) {
|
|
65
|
+
this.cache.removeRefreshToken();
|
|
66
|
+
delete connection.accessToken;
|
|
67
|
+
return await this.execute(connection, credentials);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Start a new Two-Step SASL conversation.
|
|
75
|
+
// Run a PrincipalStepRequest to get the IdpInfo.
|
|
76
|
+
// Call the OIDC Human Callback with the new IdpInfo to get a new access token and optional refresh
|
|
77
|
+
// token. Drivers MUST NOT pass a cached refresh token to the callback when performing
|
|
78
|
+
// a new Two-Step conversation. Cache the new IdpInfo and refresh token in the Client Cache and the
|
|
79
|
+
// new access token in the Client Cache and Connection Cache.
|
|
80
|
+
// Attempt to authenticate using a JwtStepRequest with the new access token. Raise any errors to the user.
|
|
81
|
+
const startResponse = await this.startAuthentication(connection, credentials);
|
|
82
|
+
const conversationId = startResponse.conversationId;
|
|
83
|
+
const idpInfo = bson_1.BSON.deserialize(startResponse.payload.buffer);
|
|
84
|
+
const callbackResponse = await this.fetchAccessToken(idpInfo, credentials);
|
|
85
|
+
this.cache.put(callbackResponse, idpInfo);
|
|
86
|
+
connection.accessToken = callbackResponse.accessToken;
|
|
87
|
+
return await this.finishAuthentication(connection, credentials, callbackResponse.accessToken, conversationId);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Fetches an access token using the callback.
|
|
91
|
+
*/
|
|
92
|
+
async fetchAccessToken(idpInfo, credentials, refreshToken) {
|
|
93
|
+
const controller = new AbortController();
|
|
94
|
+
const params = {
|
|
95
|
+
timeoutContext: controller.signal,
|
|
96
|
+
version: mongodb_oidc_1.OIDC_VERSION,
|
|
97
|
+
idpInfo: idpInfo
|
|
98
|
+
};
|
|
99
|
+
if (credentials.username) {
|
|
100
|
+
params.username = credentials.username;
|
|
101
|
+
}
|
|
102
|
+
if (refreshToken) {
|
|
103
|
+
params.refreshToken = refreshToken;
|
|
104
|
+
}
|
|
105
|
+
const timeout = timeout_1.Timeout.expires(callback_workflow_1.HUMAN_TIMEOUT_MS);
|
|
106
|
+
try {
|
|
107
|
+
return await Promise.race([this.executeAndValidateCallback(params), timeout]);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (timeout_1.TimeoutError.is(error)) {
|
|
111
|
+
controller.abort();
|
|
112
|
+
throw new error_1.MongoOIDCError(`OIDC callback timed out after ${callback_workflow_1.HUMAN_TIMEOUT_MS}ms.`);
|
|
113
|
+
}
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
timeout.clear();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.HumanCallbackWorkflow = HumanCallbackWorkflow;
|
|
122
|
+
//# sourceMappingURL=human_callback_workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"human_callback_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/human_callback_workflow.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAE5B,0CAAiF;AACjF,8CAAyD;AAGzD,kDAMyB;AACzB,2DAAyE;AAGzE;;;GAGG;AACH,MAAa,qBAAsB,SAAQ,oCAAgB;IACzD;;OAEG;IACH,YAAY,KAAiB,EAAE,QAA8B;QAC3D,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,UAAsB,EAAE,WAA6B;QACjE,iDAAiD;QACjD,sGAAsG;QACtG,8EAA8E;QAC9E,uFAAuF;QACvF,2GAA2G;QAC3G,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;YAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;YAC1C,UAAU,CAAC,WAAW,GAAG,KAAK,CAAC;YAC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BAAO,CAAC,OAAO,CAAC,oCAAgB,CAAC,CAAC;QAClD,IAAI;YACF,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;SAC/E;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,sBAAY,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE;gBAC1B,UAAU,CAAC,KAAK,EAAE,CAAC;gBACnB,MAAM,IAAI,sBAAc,CAAC,iCAAiC,oCAAgB,KAAK,CAAC,CAAC;aAClF;YACD,MAAM,KAAK,CAAC;SACb;gBAAS;YACR,OAAO,CAAC,KAAK,EAAE,CAAC;SACjB;IACH,CAAC;CACF;AAzHD,sDAyHC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MachineWorkflow = void 0;
|
|
4
|
+
const promises_1 = require("timers/promises");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
const command_builders_1 = require("./command_builders");
|
|
7
|
+
/** The time to throttle callback calls. */
|
|
8
|
+
const THROTTLE_MS = 100;
|
|
9
|
+
/**
|
|
10
|
+
* Common behaviour for OIDC machine workflows.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
class MachineWorkflow {
|
|
14
|
+
/**
|
|
15
|
+
* Instantiate the machine workflow.
|
|
16
|
+
*/
|
|
17
|
+
constructor(cache) {
|
|
18
|
+
this.cache = cache;
|
|
19
|
+
this.callback = this.withLock(this.getToken.bind(this));
|
|
20
|
+
this.lastExecutionTime = Date.now() - THROTTLE_MS;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Execute the workflow. Gets the token from the subclass implementation.
|
|
24
|
+
*/
|
|
25
|
+
async execute(connection, credentials) {
|
|
26
|
+
const token = await this.getTokenFromCacheOrEnv(connection, credentials);
|
|
27
|
+
const command = (0, command_builders_1.finishCommandDocument)(token);
|
|
28
|
+
await connection.command((0, utils_1.ns)(credentials.source), command, undefined);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reauthenticate on a machine workflow just grabs the token again since the server
|
|
32
|
+
* has said the current access token is invalid or expired.
|
|
33
|
+
*/
|
|
34
|
+
async reauthenticate(connection, credentials) {
|
|
35
|
+
if (this.cache.hasAccessToken) {
|
|
36
|
+
// Reauthentication implies the token has expired.
|
|
37
|
+
if (connection.accessToken === this.cache.getAccessToken()) {
|
|
38
|
+
// If connection's access token is the same as the cache's, remove
|
|
39
|
+
// the token from the cache and connection.
|
|
40
|
+
this.cache.removeAccessToken();
|
|
41
|
+
delete connection.accessToken;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// If the connection's access token is different from the cache's, set
|
|
45
|
+
// the cache's token on the connection and do not remove from the
|
|
46
|
+
// cache.
|
|
47
|
+
connection.accessToken = this.cache.getAccessToken();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
await this.execute(connection, credentials);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the document to add for speculative authentication.
|
|
54
|
+
*/
|
|
55
|
+
async speculativeAuth(connection, credentials) {
|
|
56
|
+
// The spec states only cached access tokens can use speculative auth.
|
|
57
|
+
if (!this.cache.hasAccessToken) {
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
const token = await this.getTokenFromCacheOrEnv(connection, credentials);
|
|
61
|
+
const document = (0, command_builders_1.finishCommandDocument)(token);
|
|
62
|
+
document.db = credentials.source;
|
|
63
|
+
return { speculativeAuthenticate: document };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the token from the cache or environment.
|
|
67
|
+
*/
|
|
68
|
+
async getTokenFromCacheOrEnv(connection, credentials) {
|
|
69
|
+
if (this.cache.hasAccessToken) {
|
|
70
|
+
return this.cache.getAccessToken();
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const token = await this.callback(credentials);
|
|
74
|
+
this.cache.put({ accessToken: token.access_token, expiresInSeconds: token.expires_in });
|
|
75
|
+
// Put the access token on the connection as well.
|
|
76
|
+
connection.accessToken = token.access_token;
|
|
77
|
+
return token.access_token;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Ensure the callback is only executed one at a time, and throttled to
|
|
82
|
+
* only once per 100ms.
|
|
83
|
+
*/
|
|
84
|
+
withLock(callback) {
|
|
85
|
+
let lock = Promise.resolve();
|
|
86
|
+
return async (credentials) => {
|
|
87
|
+
// We do this to ensure that we would never return the result of the
|
|
88
|
+
// previous lock, only the current callback's value would get returned.
|
|
89
|
+
await lock;
|
|
90
|
+
lock = lock
|
|
91
|
+
// eslint-disable-next-line github/no-then
|
|
92
|
+
.catch(() => null)
|
|
93
|
+
// eslint-disable-next-line github/no-then
|
|
94
|
+
.then(async () => {
|
|
95
|
+
const difference = Date.now() - this.lastExecutionTime;
|
|
96
|
+
if (difference <= THROTTLE_MS) {
|
|
97
|
+
await (0, promises_1.setTimeout)(THROTTLE_MS - difference);
|
|
98
|
+
}
|
|
99
|
+
this.lastExecutionTime = Date.now();
|
|
100
|
+
return await callback(credentials);
|
|
101
|
+
});
|
|
102
|
+
return await lock;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.MachineWorkflow = MachineWorkflow;
|
|
107
|
+
//# sourceMappingURL=machine_workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/machine_workflow.ts"],"names":[],"mappings":";;;AACA,8CAA6C;AAE7C,0CAAoC;AAIpC,yDAA2D;AAG3D,2CAA2C;AAC3C,MAAM,WAAW,GAAG,GAAG,CAAC;AAcxB;;;GAGG;AACH,MAAsB,eAAe;IAKnC;;OAEG;IACH,YAAY,KAAiB;QAC3B,IAAI,CAAC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B,CAAC;gBACvD,IAAI,UAAU,IAAI,WAAW,EAAE;oBAC7B,MAAM,IAAA,qBAAU,EAAC,WAAW,GAAG,UAAU,CAAC,CAAC;iBAC5C;gBACD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACpC,OAAO,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;YACL,OAAO,MAAM,IAAI,CAAC;QACpB,CAAC,CAAC;IACJ,CAAC;CAMF;AA3GD,0CA2GC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenCache = void 0;
|
|
4
|
+
const error_1 = require("../../../error");
|
|
5
|
+
class MongoOIDCError extends error_1.MongoDriverError {
|
|
6
|
+
}
|
|
7
|
+
/** @internal */
|
|
8
|
+
class TokenCache {
|
|
9
|
+
get hasAccessToken() {
|
|
10
|
+
return !!this.accessToken;
|
|
11
|
+
}
|
|
12
|
+
get hasRefreshToken() {
|
|
13
|
+
return !!this.refreshToken;
|
|
14
|
+
}
|
|
15
|
+
get hasIdpInfo() {
|
|
16
|
+
return !!this.idpInfo;
|
|
17
|
+
}
|
|
18
|
+
getAccessToken() {
|
|
19
|
+
if (!this.accessToken) {
|
|
20
|
+
throw new MongoOIDCError('Attempted to get an access token when none exists.');
|
|
21
|
+
}
|
|
22
|
+
return this.accessToken;
|
|
23
|
+
}
|
|
24
|
+
getRefreshToken() {
|
|
25
|
+
if (!this.refreshToken) {
|
|
26
|
+
throw new MongoOIDCError('Attempted to get a refresh token when none exists.');
|
|
27
|
+
}
|
|
28
|
+
return this.refreshToken;
|
|
29
|
+
}
|
|
30
|
+
getIdpInfo() {
|
|
31
|
+
if (!this.idpInfo) {
|
|
32
|
+
throw new MongoOIDCError('Attempted to get IDP information when none exists.');
|
|
33
|
+
}
|
|
34
|
+
return this.idpInfo;
|
|
35
|
+
}
|
|
36
|
+
put(response, idpInfo) {
|
|
37
|
+
this.accessToken = response.accessToken;
|
|
38
|
+
this.refreshToken = response.refreshToken;
|
|
39
|
+
this.expiresInSeconds = response.expiresInSeconds;
|
|
40
|
+
if (idpInfo) {
|
|
41
|
+
this.idpInfo = idpInfo;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
removeAccessToken() {
|
|
45
|
+
this.accessToken = undefined;
|
|
46
|
+
}
|
|
47
|
+
removeRefreshToken() {
|
|
48
|
+
this.refreshToken = undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.TokenCache = TokenCache;
|
|
52
|
+
//# sourceMappingURL=token_cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token_cache.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/token_cache.ts"],"names":[],"mappings":";;;AAAA,0CAAkD;AAGlD,MAAM,cAAe,SAAQ,wBAAgB;CAAG;AAEhD,gBAAgB;AAChB,MAAa,UAAU;IAMrB,IAAI,cAAc;QAChB,OAAO,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,MAAM,IAAI,cAAc,CAAC,oDAAoD,CAAC,CAAC;SAChF;QACD,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,eAAe;QACb,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACtB,MAAM,IAAI,cAAc,CAAC,oDAAoD,CAAC,CAAC;SAChF;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,IAAI,cAAc,CAAC,oDAAoD,CAAC,CAAC;SAChF;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,GAAG,CAAC,QAAsB,EAAE,OAAiB;QAC3C,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;QACxC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;QAC1C,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC;QAClD,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACxB;IACH,CAAC;IAED,iBAAiB;QACf,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,kBAAkB;QAChB,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;IAChC,CAAC;CACF;AAvDD,gCAuDC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenMachineWorkflow = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const error_1 = require("../../../error");
|
|
6
|
+
const machine_workflow_1 = require("./machine_workflow");
|
|
7
|
+
/** Error for when the token is missing in the environment. */
|
|
8
|
+
const TOKEN_MISSING_ERROR = 'OIDC_TOKEN_FILE must be set in the environment.';
|
|
9
|
+
/**
|
|
10
|
+
* Device workflow implementation for AWS.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
class TokenMachineWorkflow extends machine_workflow_1.MachineWorkflow {
|
|
15
|
+
/**
|
|
16
|
+
* Instantiate the machine workflow.
|
|
17
|
+
*/
|
|
18
|
+
constructor(cache) {
|
|
19
|
+
super(cache);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the token from the environment.
|
|
23
|
+
*/
|
|
24
|
+
async getToken() {
|
|
25
|
+
const tokenFile = process.env.OIDC_TOKEN_FILE;
|
|
26
|
+
if (!tokenFile) {
|
|
27
|
+
throw new error_1.MongoAWSError(TOKEN_MISSING_ERROR);
|
|
28
|
+
}
|
|
29
|
+
const token = await fs.promises.readFile(tokenFile, 'utf8');
|
|
30
|
+
return { access_token: token };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.TokenMachineWorkflow = TokenMachineWorkflow;
|
|
34
|
+
//# sourceMappingURL=token_machine_workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token_machine_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/token_machine_workflow.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AAEzB,0CAA+C;AAC/C,yDAAuE;AAGvE,8DAA8D;AAC9D,MAAM,mBAAmB,GAAG,iDAAiD,CAAC;AAE9E;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,kCAAe;IACvD;;OAEG;IACH,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;QAC9C,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,qBAAa,CAAC,mBAAmB,CAAC,CAAC;SAC9C;QACD,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC5D,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACjC,CAAC;CACF;AAnBD,oDAmBC"}
|
|
@@ -1,45 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MongoDBOIDC = exports.OIDC_WORKFLOWS = void 0;
|
|
3
|
+
exports.MongoDBOIDC = exports.OIDC_WORKFLOWS = exports.OIDC_VERSION = void 0;
|
|
4
4
|
const error_1 = require("../../error");
|
|
5
5
|
const auth_provider_1 = require("./auth_provider");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
const azure_machine_workflow_1 = require("./mongodb_oidc/azure_machine_workflow");
|
|
7
|
+
const gcp_machine_workflow_1 = require("./mongodb_oidc/gcp_machine_workflow");
|
|
8
|
+
const token_cache_1 = require("./mongodb_oidc/token_cache");
|
|
9
|
+
const token_machine_workflow_1 = require("./mongodb_oidc/token_machine_workflow");
|
|
9
10
|
/** Error when credentials are missing. */
|
|
10
11
|
const MISSING_CREDENTIALS_ERROR = 'AuthContext must provide credentials.';
|
|
12
|
+
/** The current version of OIDC implementation. */
|
|
13
|
+
exports.OIDC_VERSION = 1;
|
|
11
14
|
/** @internal */
|
|
12
15
|
exports.OIDC_WORKFLOWS = new Map();
|
|
13
|
-
exports.OIDC_WORKFLOWS.set('
|
|
14
|
-
exports.OIDC_WORKFLOWS.set('
|
|
15
|
-
exports.OIDC_WORKFLOWS.set('
|
|
16
|
+
exports.OIDC_WORKFLOWS.set('test', () => new token_machine_workflow_1.TokenMachineWorkflow(new token_cache_1.TokenCache()));
|
|
17
|
+
exports.OIDC_WORKFLOWS.set('azure', () => new azure_machine_workflow_1.AzureMachineWorkflow(new token_cache_1.TokenCache()));
|
|
18
|
+
exports.OIDC_WORKFLOWS.set('gcp', () => new gcp_machine_workflow_1.GCPMachineWorkflow(new token_cache_1.TokenCache()));
|
|
16
19
|
/**
|
|
17
20
|
* OIDC auth provider.
|
|
18
|
-
* @experimental
|
|
19
21
|
*/
|
|
20
22
|
class MongoDBOIDC extends auth_provider_1.AuthProvider {
|
|
21
23
|
/**
|
|
22
24
|
* Instantiate the auth provider.
|
|
23
25
|
*/
|
|
24
|
-
constructor() {
|
|
26
|
+
constructor(workflow) {
|
|
25
27
|
super();
|
|
28
|
+
if (!workflow) {
|
|
29
|
+
throw new error_1.MongoInvalidArgumentError('No workflow provided to the OIDC auth provider.');
|
|
30
|
+
}
|
|
31
|
+
this.workflow = workflow;
|
|
26
32
|
}
|
|
27
33
|
/**
|
|
28
34
|
* Authenticate using OIDC
|
|
29
35
|
*/
|
|
30
36
|
async auth(authContext) {
|
|
31
37
|
const { connection, reauthenticating, response } = authContext;
|
|
38
|
+
if (response?.speculativeAuthenticate?.done) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
32
41
|
const credentials = getCredentials(authContext);
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
if (reauthenticating) {
|
|
43
|
+
await this.workflow.reauthenticate(connection, credentials);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
await this.workflow.execute(connection, credentials, response);
|
|
47
|
+
}
|
|
35
48
|
}
|
|
36
49
|
/**
|
|
37
50
|
* Add the speculative auth for the initial handshake.
|
|
38
51
|
*/
|
|
39
52
|
async prepare(handshakeDoc, authContext) {
|
|
53
|
+
const { connection } = authContext;
|
|
40
54
|
const credentials = getCredentials(authContext);
|
|
41
|
-
const
|
|
42
|
-
const result = await workflow.speculativeAuth(credentials);
|
|
55
|
+
const result = await this.workflow.speculativeAuth(connection, credentials);
|
|
43
56
|
return { ...handshakeDoc, ...result };
|
|
44
57
|
}
|
|
45
58
|
}
|
|
@@ -54,15 +67,4 @@ function getCredentials(authContext) {
|
|
|
54
67
|
}
|
|
55
68
|
return credentials;
|
|
56
69
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Gets either a device workflow or callback workflow.
|
|
59
|
-
*/
|
|
60
|
-
function getWorkflow(credentials) {
|
|
61
|
-
const providerName = credentials.mechanismProperties.PROVIDER_NAME;
|
|
62
|
-
const workflow = exports.OIDC_WORKFLOWS.get(providerName || 'callback');
|
|
63
|
-
if (!workflow) {
|
|
64
|
-
throw new error_1.MongoInvalidArgumentError(`Could not load workflow for provider ${credentials.mechanismProperties.PROVIDER_NAME}`);
|
|
65
|
-
}
|
|
66
|
-
return workflow;
|
|
67
|
-
}
|
|
68
70
|
//# sourceMappingURL=mongodb_oidc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb_oidc.js","sourceRoot":"","sources":["../../../src/cmap/auth/mongodb_oidc.ts"],"names":[],"mappings":";;;AAEA,uCAAsF;AAGtF,mDAAiE;AAEjE,8EAAyE;AACzE,
|
|
1
|
+
{"version":3,"file":"mongodb_oidc.js","sourceRoot":"","sources":["../../../src/cmap/auth/mongodb_oidc.ts"],"names":[],"mappings":";;;AAEA,uCAAsF;AAGtF,mDAAiE;AAEjE,kFAA6E;AAC7E,8EAAyE;AACzE,4DAAwD;AACxD,kFAA6E;AAE7E,0CAA0C;AAC1C,MAAM,yBAAyB,GAAG,uCAAuC,CAAC;AA2E1E,kDAAkD;AACrC,QAAA,YAAY,GAAG,CAAC,CAAC;AA2B9B,gBAAgB;AACH,QAAA,cAAc,GAAyC,IAAI,GAAG,EAAE,CAAC;AAC9E,sBAAc,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,6CAAoB,CAAC,IAAI,wBAAU,EAAE,CAAC,CAAC,CAAC;AAC7E,sBAAc,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,6CAAoB,CAAC,IAAI,wBAAU,EAAE,CAAC,CAAC,CAAC;AAC9E,sBAAc,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,yCAAkB,CAAC,IAAI,wBAAU,EAAE,CAAC,CAAC,CAAC;AAE1E;;GAEG;AACH,MAAa,WAAY,SAAQ,4BAAY;IAG3C;;OAEG;IACH,YAAY,QAAmB;QAC7B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,iCAAyB,CAAC,iDAAiD,CAAC,CAAC;SACxF;QACD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;OAEG;IACM,KAAK,CAAC,IAAI,CAAC,WAAwB;QAC1C,MAAM,EA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cAAc,EAAE,QAAQ;IACxB,aAAa,EAAE,OAAO;IACtB,kBAAkB,EAAE,aAAa;IACjC,oBAAoB,EAAE,eAAe;IACrC,YAAY,EAAE,cAAc;IAC5B,
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../../src/cmap/auth/providers.ts"],"names":[],"mappings":";;;AAAA,cAAc;AACD,QAAA,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,YAAY;IACxB,eAAe,EAAE,SAAS;IAC1B,cAAc,EAAE,QAAQ;IACxB,aAAa,EAAE,OAAO;IACtB,kBAAkB,EAAE,aAAa;IACjC,oBAAoB,EAAE,eAAe;IACrC,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;CACpB,CAAC,CAAC;AAKZ,gBAAgB;AACH,QAAA,4BAA4B,GAAG,IAAI,GAAG,CAAgB;IACjE,qBAAa,CAAC,cAAc;IAC5B,qBAAa,CAAC,WAAW;IACzB,qBAAa,CAAC,YAAY;IAC1B,qBAAa,CAAC,YAAY;CAC3B,CAAC,CAAC"}
|
package/lib/cmap/connect.js
CHANGED
|
@@ -52,7 +52,7 @@ async function performInitialHandshake(conn, options) {
|
|
|
52
52
|
const credentials = options.credentials;
|
|
53
53
|
if (credentials) {
|
|
54
54
|
if (!(credentials.mechanism === providers_1.AuthMechanism.MONGODB_DEFAULT) &&
|
|
55
|
-
!options.authProviders.getOrCreateProvider(credentials.mechanism)) {
|
|
55
|
+
!options.authProviders.getOrCreateProvider(credentials.mechanism, credentials.mechanismProperties)) {
|
|
56
56
|
throw new error_1.MongoInvalidArgumentError(`AuthMechanism '${credentials.mechanism}' not supported`);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -93,7 +93,7 @@ async function performInitialHandshake(conn, options) {
|
|
|
93
93
|
// store the response on auth context
|
|
94
94
|
authContext.response = response;
|
|
95
95
|
const resolvedCredentials = credentials.resolveAuthMechanism(response);
|
|
96
|
-
const provider = options.authProviders.getOrCreateProvider(resolvedCredentials.mechanism);
|
|
96
|
+
const provider = options.authProviders.getOrCreateProvider(resolvedCredentials.mechanism, resolvedCredentials.mechanismProperties);
|
|
97
97
|
if (!provider) {
|
|
98
98
|
throw new error_1.MongoInvalidArgumentError(`No AuthProvider for ${resolvedCredentials.mechanism} defined.`);
|
|
99
99
|
}
|
|
@@ -138,14 +138,14 @@ async function prepareHandshakeDocument(authContext) {
|
|
|
138
138
|
if (credentials) {
|
|
139
139
|
if (credentials.mechanism === providers_1.AuthMechanism.MONGODB_DEFAULT && credentials.username) {
|
|
140
140
|
handshakeDoc.saslSupportedMechs = `${credentials.source}.${credentials.username}`;
|
|
141
|
-
const provider = authContext.options.authProviders.getOrCreateProvider(providers_1.AuthMechanism.MONGODB_SCRAM_SHA256);
|
|
141
|
+
const provider = authContext.options.authProviders.getOrCreateProvider(providers_1.AuthMechanism.MONGODB_SCRAM_SHA256, credentials.mechanismProperties);
|
|
142
142
|
if (!provider) {
|
|
143
143
|
// This auth mechanism is always present.
|
|
144
144
|
throw new error_1.MongoInvalidArgumentError(`No AuthProvider for ${providers_1.AuthMechanism.MONGODB_SCRAM_SHA256} defined.`);
|
|
145
145
|
}
|
|
146
146
|
return await provider.prepare(handshakeDoc, authContext);
|
|
147
147
|
}
|
|
148
|
-
const provider = authContext.options.authProviders.getOrCreateProvider(credentials.mechanism);
|
|
148
|
+
const provider = authContext.options.authProviders.getOrCreateProvider(credentials.mechanism, credentials.mechanismProperties);
|
|
149
149
|
if (!provider) {
|
|
150
150
|
throw new error_1.MongoInvalidArgumentError(`No AuthProvider for ${credentials.mechanism} defined.`);
|
|
151
151
|
}
|