@depup/mongodb 7.1.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +201 -0
- package/README.md +33 -0
- package/etc/prepare.js +12 -0
- package/lib/admin.js +136 -0
- package/lib/admin.js.map +1 -0
- package/lib/bson.js +85 -0
- package/lib/bson.js.map +1 -0
- package/lib/bulk/common.js +835 -0
- package/lib/bulk/common.js.map +1 -0
- package/lib/bulk/ordered.js +67 -0
- package/lib/bulk/ordered.js.map +1 -0
- package/lib/bulk/unordered.js +92 -0
- package/lib/bulk/unordered.js.map +1 -0
- package/lib/change_stream.js +513 -0
- package/lib/change_stream.js.map +1 -0
- package/lib/client-side-encryption/auto_encrypter.js +272 -0
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -0
- package/lib/client-side-encryption/client_encryption.js +609 -0
- package/lib/client-side-encryption/client_encryption.js.map +1 -0
- package/lib/client-side-encryption/errors.js +138 -0
- package/lib/client-side-encryption/errors.js.map +1 -0
- package/lib/client-side-encryption/mongocryptd_manager.js +85 -0
- package/lib/client-side-encryption/mongocryptd_manager.js.map +1 -0
- package/lib/client-side-encryption/providers/aws.js +23 -0
- package/lib/client-side-encryption/providers/aws.js.map +1 -0
- package/lib/client-side-encryption/providers/azure.js +132 -0
- package/lib/client-side-encryption/providers/azure.js.map +1 -0
- package/lib/client-side-encryption/providers/gcp.js +16 -0
- package/lib/client-side-encryption/providers/gcp.js.map +1 -0
- package/lib/client-side-encryption/providers/index.js +43 -0
- package/lib/client-side-encryption/providers/index.js.map +1 -0
- package/lib/client-side-encryption/state_machine.js +427 -0
- package/lib/client-side-encryption/state_machine.js.map +1 -0
- package/lib/cmap/auth/auth_provider.js +51 -0
- package/lib/cmap/auth/auth_provider.js.map +1 -0
- package/lib/cmap/auth/aws4.js +161 -0
- package/lib/cmap/auth/aws4.js.map +1 -0
- package/lib/cmap/auth/aws_temporary_credentials.js +103 -0
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
- package/lib/cmap/auth/gssapi.js +155 -0
- package/lib/cmap/auth/gssapi.js.map +1 -0
- package/lib/cmap/auth/mongo_credentials.js +169 -0
- package/lib/cmap/auth/mongo_credentials.js.map +1 -0
- package/lib/cmap/auth/mongodb_aws.js +128 -0
- package/lib/cmap/auth/mongodb_aws.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +84 -0
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +62 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +141 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/command_builders.js +44 -0
- package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +39 -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/k8s_machine_workflow.js +32 -0
- package/lib/cmap/auth/mongodb_oidc/k8s_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 +23 -0
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc.js +73 -0
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -0
- package/lib/cmap/auth/plain.js +26 -0
- package/lib/cmap/auth/plain.js.map +1 -0
- package/lib/cmap/auth/providers.js +22 -0
- package/lib/cmap/auth/providers.js.map +1 -0
- package/lib/cmap/auth/scram.js +254 -0
- package/lib/cmap/auth/scram.js.map +1 -0
- package/lib/cmap/auth/x509.js +36 -0
- package/lib/cmap/auth/x509.js.map +1 -0
- package/lib/cmap/command_monitoring_events.js +223 -0
- package/lib/cmap/command_monitoring_events.js.map +1 -0
- package/lib/cmap/commands.js +535 -0
- package/lib/cmap/commands.js.map +1 -0
- package/lib/cmap/connect.js +381 -0
- package/lib/cmap/connect.js.map +1 -0
- package/lib/cmap/connection.js +571 -0
- package/lib/cmap/connection.js.map +1 -0
- package/lib/cmap/connection_pool.js +558 -0
- package/lib/cmap/connection_pool.js.map +1 -0
- package/lib/cmap/connection_pool_events.js +190 -0
- package/lib/cmap/connection_pool_events.js.map +1 -0
- package/lib/cmap/errors.js +108 -0
- package/lib/cmap/errors.js.map +1 -0
- package/lib/cmap/handshake/client_metadata.js +242 -0
- package/lib/cmap/handshake/client_metadata.js.map +1 -0
- package/lib/cmap/metrics.js +62 -0
- package/lib/cmap/metrics.js.map +1 -0
- package/lib/cmap/stream_description.js +70 -0
- package/lib/cmap/stream_description.js.map +1 -0
- package/lib/cmap/wire_protocol/compression.js +178 -0
- package/lib/cmap/wire_protocol/compression.js.map +1 -0
- package/lib/cmap/wire_protocol/constants.js +21 -0
- package/lib/cmap/wire_protocol/constants.js.map +1 -0
- package/lib/cmap/wire_protocol/on_data.js +111 -0
- package/lib/cmap/wire_protocol/on_data.js.map +1 -0
- package/lib/cmap/wire_protocol/on_demand/document.js +222 -0
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
- package/lib/cmap/wire_protocol/responses.js +315 -0
- package/lib/cmap/wire_protocol/responses.js.map +1 -0
- package/lib/cmap/wire_protocol/shared.js +35 -0
- package/lib/cmap/wire_protocol/shared.js.map +1 -0
- package/lib/collection.js +751 -0
- package/lib/collection.js.map +1 -0
- package/lib/connection_string.js +1090 -0
- package/lib/connection_string.js.map +1 -0
- package/lib/constants.js +170 -0
- package/lib/constants.js.map +1 -0
- package/lib/cursor/abstract_cursor.js +924 -0
- package/lib/cursor/abstract_cursor.js.map +1 -0
- package/lib/cursor/aggregation_cursor.js +164 -0
- package/lib/cursor/aggregation_cursor.js.map +1 -0
- package/lib/cursor/change_stream_cursor.js +104 -0
- package/lib/cursor/change_stream_cursor.js.map +1 -0
- package/lib/cursor/client_bulk_write_cursor.js +52 -0
- package/lib/cursor/client_bulk_write_cursor.js.map +1 -0
- package/lib/cursor/explainable_cursor.js +36 -0
- package/lib/cursor/explainable_cursor.js.map +1 -0
- package/lib/cursor/find_cursor.js +399 -0
- package/lib/cursor/find_cursor.js.map +1 -0
- package/lib/cursor/list_collections_cursor.js +34 -0
- package/lib/cursor/list_collections_cursor.js.map +1 -0
- package/lib/cursor/list_indexes_cursor.js +32 -0
- package/lib/cursor/list_indexes_cursor.js.map +1 -0
- package/lib/cursor/list_search_indexes_cursor.js +14 -0
- package/lib/cursor/list_search_indexes_cursor.js.map +1 -0
- package/lib/cursor/run_command_cursor.js +94 -0
- package/lib/cursor/run_command_cursor.js.map +1 -0
- package/lib/db.js +419 -0
- package/lib/db.js.map +1 -0
- package/lib/deps.js +112 -0
- package/lib/deps.js.map +1 -0
- package/lib/encrypter.js +106 -0
- package/lib/encrypter.js.map +1 -0
- package/lib/error.js +1380 -0
- package/lib/error.js.map +1 -0
- package/lib/explain.js +59 -0
- package/lib/explain.js.map +1 -0
- package/lib/gridfs/download.js +305 -0
- package/lib/gridfs/download.js.map +1 -0
- package/lib/gridfs/index.js +164 -0
- package/lib/gridfs/index.js.map +1 -0
- package/lib/gridfs/upload.js +358 -0
- package/lib/gridfs/upload.js.map +1 -0
- package/lib/index.js +193 -0
- package/lib/index.js.map +1 -0
- package/lib/mongo_client.js +557 -0
- package/lib/mongo_client.js.map +1 -0
- package/lib/mongo_client_auth_providers.js +80 -0
- package/lib/mongo_client_auth_providers.js.map +1 -0
- package/lib/mongo_logger.js +655 -0
- package/lib/mongo_logger.js.map +1 -0
- package/lib/mongo_types.js +56 -0
- package/lib/mongo_types.js.map +1 -0
- package/lib/operations/aggregate.js +90 -0
- package/lib/operations/aggregate.js.map +1 -0
- package/lib/operations/client_bulk_write/client_bulk_write.js +51 -0
- package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -0
- package/lib/operations/client_bulk_write/command_builder.js +340 -0
- package/lib/operations/client_bulk_write/command_builder.js.map +1 -0
- package/lib/operations/client_bulk_write/common.js +3 -0
- package/lib/operations/client_bulk_write/common.js.map +1 -0
- package/lib/operations/client_bulk_write/executor.js +120 -0
- package/lib/operations/client_bulk_write/executor.js.map +1 -0
- package/lib/operations/client_bulk_write/results_merger.js +204 -0
- package/lib/operations/client_bulk_write/results_merger.js.map +1 -0
- package/lib/operations/command.js +83 -0
- package/lib/operations/command.js.map +1 -0
- package/lib/operations/count.js +45 -0
- package/lib/operations/count.js.map +1 -0
- package/lib/operations/create_collection.js +109 -0
- package/lib/operations/create_collection.js.map +1 -0
- package/lib/operations/delete.js +125 -0
- package/lib/operations/delete.js.map +1 -0
- package/lib/operations/distinct.js +61 -0
- package/lib/operations/distinct.js.map +1 -0
- package/lib/operations/drop.js +93 -0
- package/lib/operations/drop.js.map +1 -0
- package/lib/operations/end_sessions.js +34 -0
- package/lib/operations/end_sessions.js.map +1 -0
- package/lib/operations/estimated_document_count.js +41 -0
- package/lib/operations/estimated_document_count.js.map +1 -0
- package/lib/operations/execute_operation.js +239 -0
- package/lib/operations/execute_operation.js.map +1 -0
- package/lib/operations/find.js +148 -0
- package/lib/operations/find.js.map +1 -0
- package/lib/operations/find_and_modify.js +158 -0
- package/lib/operations/find_and_modify.js.map +1 -0
- package/lib/operations/get_more.js +62 -0
- package/lib/operations/get_more.js.map +1 -0
- package/lib/operations/indexes.js +186 -0
- package/lib/operations/indexes.js.map +1 -0
- package/lib/operations/insert.js +70 -0
- package/lib/operations/insert.js.map +1 -0
- package/lib/operations/kill_cursors.js +43 -0
- package/lib/operations/kill_cursors.js.map +1 -0
- package/lib/operations/list_collections.js +53 -0
- package/lib/operations/list_collections.js.map +1 -0
- package/lib/operations/list_databases.js +40 -0
- package/lib/operations/list_databases.js.map +1 -0
- package/lib/operations/operation.js +102 -0
- package/lib/operations/operation.js.map +1 -0
- package/lib/operations/profiling_level.js +43 -0
- package/lib/operations/profiling_level.js.map +1 -0
- package/lib/operations/remove_user.js +27 -0
- package/lib/operations/remove_user.js.map +1 -0
- package/lib/operations/rename.js +38 -0
- package/lib/operations/rename.js.map +1 -0
- package/lib/operations/run_command.js +47 -0
- package/lib/operations/run_command.js.map +1 -0
- package/lib/operations/search_indexes/create.js +33 -0
- package/lib/operations/search_indexes/create.js.map +1 -0
- package/lib/operations/search_indexes/drop.js +43 -0
- package/lib/operations/search_indexes/drop.js.map +1 -0
- package/lib/operations/search_indexes/update.js +35 -0
- package/lib/operations/search_indexes/update.js.map +1 -0
- package/lib/operations/set_profiling_level.js +53 -0
- package/lib/operations/set_profiling_level.js.map +1 -0
- package/lib/operations/stats.js +27 -0
- package/lib/operations/stats.js.map +1 -0
- package/lib/operations/update.js +188 -0
- package/lib/operations/update.js.map +1 -0
- package/lib/operations/validate_collection.js +37 -0
- package/lib/operations/validate_collection.js.map +1 -0
- package/lib/read_concern.js +73 -0
- package/lib/read_concern.js.map +1 -0
- package/lib/read_preference.js +191 -0
- package/lib/read_preference.js.map +1 -0
- package/lib/sdam/common.js +49 -0
- package/lib/sdam/common.js.map +1 -0
- package/lib/sdam/events.js +146 -0
- package/lib/sdam/events.js.map +1 -0
- package/lib/sdam/monitor.js +544 -0
- package/lib/sdam/monitor.js.map +1 -0
- package/lib/sdam/server.js +404 -0
- package/lib/sdam/server.js.map +1 -0
- package/lib/sdam/server_description.js +204 -0
- package/lib/sdam/server_description.js.map +1 -0
- package/lib/sdam/server_selection.js +294 -0
- package/lib/sdam/server_selection.js.map +1 -0
- package/lib/sdam/server_selection_events.js +85 -0
- package/lib/sdam/server_selection_events.js.map +1 -0
- package/lib/sdam/srv_polling.js +108 -0
- package/lib/sdam/srv_polling.js.map +1 -0
- package/lib/sdam/topology.js +652 -0
- package/lib/sdam/topology.js.map +1 -0
- package/lib/sdam/topology_description.js +383 -0
- package/lib/sdam/topology_description.js.map +1 -0
- package/lib/sessions.js +892 -0
- package/lib/sessions.js.map +1 -0
- package/lib/sort.js +103 -0
- package/lib/sort.js.map +1 -0
- package/lib/timeout.js +296 -0
- package/lib/timeout.js.map +1 -0
- package/lib/transactions.js +135 -0
- package/lib/transactions.js.map +1 -0
- package/lib/utils.js +1163 -0
- package/lib/utils.js.map +1 -0
- package/lib/write_concern.js +100 -0
- package/lib/write_concern.js.map +1 -0
- package/mongodb.d.ts +9018 -0
- package/package.json +197 -0
- package/src/admin.ts +173 -0
- package/src/bson.ts +149 -0
- package/src/bulk/common.ts +1251 -0
- package/src/bulk/ordered.ts +83 -0
- package/src/bulk/unordered.ts +115 -0
- package/src/change_stream.ts +1160 -0
- package/src/client-side-encryption/auto_encrypter.ts +469 -0
- package/src/client-side-encryption/client_encryption.ts +1150 -0
- package/src/client-side-encryption/errors.ts +144 -0
- package/src/client-side-encryption/mongocryptd_manager.ts +100 -0
- package/src/client-side-encryption/providers/aws.ts +33 -0
- package/src/client-side-encryption/providers/azure.ts +181 -0
- package/src/client-side-encryption/providers/gcp.ts +16 -0
- package/src/client-side-encryption/providers/index.ts +207 -0
- package/src/client-side-encryption/state_machine.ts +651 -0
- package/src/cmap/auth/auth_provider.ts +77 -0
- package/src/cmap/auth/aws4.ts +207 -0
- package/src/cmap/auth/aws_temporary_credentials.ts +129 -0
- package/src/cmap/auth/gssapi.ts +203 -0
- package/src/cmap/auth/mongo_credentials.ts +292 -0
- package/src/cmap/auth/mongodb_aws.ts +179 -0
- package/src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts +88 -0
- package/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts +73 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +188 -0
- package/src/cmap/auth/mongodb_oidc/command_builders.ts +53 -0
- package/src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts +46 -0
- package/src/cmap/auth/mongodb_oidc/human_callback_workflow.ts +141 -0
- package/src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts +31 -0
- package/src/cmap/auth/mongodb_oidc/token_cache.ts +62 -0
- package/src/cmap/auth/mongodb_oidc/token_machine_workflow.ts +22 -0
- package/src/cmap/auth/mongodb_oidc.ts +185 -0
- package/src/cmap/auth/plain.ts +25 -0
- package/src/cmap/auth/providers.ts +22 -0
- package/src/cmap/auth/scram.ts +344 -0
- package/src/cmap/auth/x509.ts +43 -0
- package/src/cmap/command_monitoring_events.ts +316 -0
- package/src/cmap/commands.ts +788 -0
- package/src/cmap/connect.ts +518 -0
- package/src/cmap/connection.ts +931 -0
- package/src/cmap/connection_pool.ts +831 -0
- package/src/cmap/connection_pool_events.ts +300 -0
- package/src/cmap/errors.ts +119 -0
- package/src/cmap/handshake/client_metadata.ts +353 -0
- package/src/cmap/metrics.ts +58 -0
- package/src/cmap/stream_description.ts +96 -0
- package/src/cmap/wire_protocol/compression.ts +211 -0
- package/src/cmap/wire_protocol/constants.ts +17 -0
- package/src/cmap/wire_protocol/on_data.ts +139 -0
- package/src/cmap/wire_protocol/on_demand/document.ts +358 -0
- package/src/cmap/wire_protocol/responses.ts +393 -0
- package/src/cmap/wire_protocol/shared.ts +48 -0
- package/src/collection.ts +1314 -0
- package/src/connection_string.ts +1297 -0
- package/src/constants.ts +176 -0
- package/src/cursor/abstract_cursor.ts +1247 -0
- package/src/cursor/aggregation_cursor.ts +245 -0
- package/src/cursor/change_stream_cursor.ts +171 -0
- package/src/cursor/client_bulk_write_cursor.ts +83 -0
- package/src/cursor/explainable_cursor.ts +51 -0
- package/src/cursor/find_cursor.ts +497 -0
- package/src/cursor/list_collections_cursor.ts +50 -0
- package/src/cursor/list_indexes_cursor.ts +37 -0
- package/src/cursor/list_search_indexes_cursor.ts +20 -0
- package/src/cursor/run_command_cursor.ts +178 -0
- package/src/db.ts +621 -0
- package/src/deps.ts +227 -0
- package/src/encrypter.ts +127 -0
- package/src/error.ts +1567 -0
- package/src/explain.ts +124 -0
- package/src/gridfs/download.ts +483 -0
- package/src/gridfs/index.ts +264 -0
- package/src/gridfs/upload.ts +537 -0
- package/src/index.ts +633 -0
- package/src/mongo_client.ts +1155 -0
- package/src/mongo_client_auth_providers.ts +87 -0
- package/src/mongo_logger.ts +1081 -0
- package/src/mongo_types.ts +678 -0
- package/src/operations/aggregate.ts +153 -0
- package/src/operations/client_bulk_write/client_bulk_write.ts +72 -0
- package/src/operations/client_bulk_write/command_builder.ts +487 -0
- package/src/operations/client_bulk_write/common.ts +276 -0
- package/src/operations/client_bulk_write/executor.ts +149 -0
- package/src/operations/client_bulk_write/results_merger.ts +260 -0
- package/src/operations/command.ts +171 -0
- package/src/operations/count.ts +74 -0
- package/src/operations/create_collection.ts +218 -0
- package/src/operations/delete.ts +183 -0
- package/src/operations/distinct.ts +92 -0
- package/src/operations/drop.ts +130 -0
- package/src/operations/end_sessions.ts +44 -0
- package/src/operations/estimated_document_count.ts +61 -0
- package/src/operations/execute_operation.ts +319 -0
- package/src/operations/find.ts +254 -0
- package/src/operations/find_and_modify.ts +319 -0
- package/src/operations/get_more.ts +108 -0
- package/src/operations/indexes.ts +418 -0
- package/src/operations/insert.ts +108 -0
- package/src/operations/kill_cursors.ts +64 -0
- package/src/operations/list_collections.ts +108 -0
- package/src/operations/list_databases.ts +68 -0
- package/src/operations/operation.ts +181 -0
- package/src/operations/profiling_level.ts +46 -0
- package/src/operations/remove_user.ts +36 -0
- package/src/operations/rename.ts +60 -0
- package/src/operations/run_command.ts +79 -0
- package/src/operations/search_indexes/create.ts +56 -0
- package/src/operations/search_indexes/drop.ts +58 -0
- package/src/operations/search_indexes/update.ts +45 -0
- package/src/operations/set_profiling_level.ts +74 -0
- package/src/operations/stats.ts +37 -0
- package/src/operations/update.ts +318 -0
- package/src/operations/validate_collection.ts +50 -0
- package/src/read_concern.ts +88 -0
- package/src/read_preference.ts +256 -0
- package/src/sdam/common.ts +74 -0
- package/src/sdam/events.ts +219 -0
- package/src/sdam/monitor.ts +771 -0
- package/src/sdam/server.ts +595 -0
- package/src/sdam/server_description.ts +297 -0
- package/src/sdam/server_selection.ts +415 -0
- package/src/sdam/server_selection_events.ts +142 -0
- package/src/sdam/srv_polling.ts +146 -0
- package/src/sdam/topology.ts +1100 -0
- package/src/sdam/topology_description.ts +548 -0
- package/src/sessions.ts +1244 -0
- package/src/sort.ts +141 -0
- package/src/timeout.ts +405 -0
- package/src/transactions.ts +181 -0
- package/src/utils.ts +1434 -0
- package/src/write_concern.ts +183 -0
- package/tsconfig.json +46 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AutomatedCallbackWorkflow = void 0;
|
|
4
|
+
const error_1 = require("../../../error");
|
|
5
|
+
const timeout_1 = require("../../../timeout");
|
|
6
|
+
const mongodb_oidc_1 = require("../mongodb_oidc");
|
|
7
|
+
const callback_workflow_1 = require("./callback_workflow");
|
|
8
|
+
/**
|
|
9
|
+
* Class implementing behaviour for the non human callback workflow.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
class AutomatedCallbackWorkflow extends callback_workflow_1.CallbackWorkflow {
|
|
13
|
+
/**
|
|
14
|
+
* Instantiate the human callback workflow.
|
|
15
|
+
*/
|
|
16
|
+
constructor(cache, callback) {
|
|
17
|
+
super(cache, callback);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Execute the OIDC callback workflow.
|
|
21
|
+
*/
|
|
22
|
+
async execute(connection, credentials) {
|
|
23
|
+
// If there is a cached access token, try to authenticate with it. If
|
|
24
|
+
// authentication fails with an Authentication error (18),
|
|
25
|
+
// invalidate the access token, fetch a new access token, and try
|
|
26
|
+
// to authenticate again.
|
|
27
|
+
// If the server fails for any other reason, do not clear the cache.
|
|
28
|
+
if (this.cache.hasAccessToken) {
|
|
29
|
+
const token = this.cache.getAccessToken();
|
|
30
|
+
if (!connection.accessToken) {
|
|
31
|
+
connection.accessToken = token;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
return await this.finishAuthentication(connection, credentials, token);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (error instanceof error_1.MongoError &&
|
|
38
|
+
error.code === error_1.MONGODB_ERROR_CODES.AuthenticationFailed) {
|
|
39
|
+
this.cache.removeAccessToken();
|
|
40
|
+
return await this.execute(connection, credentials);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const response = await this.fetchAccessToken(credentials);
|
|
48
|
+
this.cache.put(response);
|
|
49
|
+
connection.accessToken = response.accessToken;
|
|
50
|
+
await this.finishAuthentication(connection, credentials, response.accessToken);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Fetches the access token using the callback.
|
|
54
|
+
*/
|
|
55
|
+
async fetchAccessToken(credentials) {
|
|
56
|
+
const controller = new AbortController();
|
|
57
|
+
const params = {
|
|
58
|
+
timeoutContext: controller.signal,
|
|
59
|
+
version: mongodb_oidc_1.OIDC_VERSION
|
|
60
|
+
};
|
|
61
|
+
if (credentials.username) {
|
|
62
|
+
params.username = credentials.username;
|
|
63
|
+
}
|
|
64
|
+
if (credentials.mechanismProperties.TOKEN_RESOURCE) {
|
|
65
|
+
params.tokenAudience = credentials.mechanismProperties.TOKEN_RESOURCE;
|
|
66
|
+
}
|
|
67
|
+
const timeout = timeout_1.Timeout.expires(callback_workflow_1.AUTOMATED_TIMEOUT_MS);
|
|
68
|
+
try {
|
|
69
|
+
return await Promise.race([this.executeAndValidateCallback(params), timeout]);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (timeout_1.TimeoutError.is(error)) {
|
|
73
|
+
controller.abort();
|
|
74
|
+
throw new error_1.MongoOIDCError(`OIDC callback timed out after ${callback_workflow_1.AUTOMATED_TIMEOUT_MS}ms.`);
|
|
75
|
+
}
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
timeout.clear();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.AutomatedCallbackWorkflow = AutomatedCallbackWorkflow;
|
|
84
|
+
//# sourceMappingURL=automated_callback_workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"automated_callback_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts"],"names":[],"mappings":";;;AAAA,0CAAiF;AACjF,8CAAyD;AAGzD,kDAKyB;AACzB,2DAA6E;AAG7E;;;GAGG;AACH,MAAa,yBAA0B,SAAQ,oCAAgB;IAC7D;;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,qEAAqE;QACrE,0DAA0D;QAC1D,iEAAiE;QACjE,yBAAyB;QACzB,oEAAoE;QACpE,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;YAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;YAC1C,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;gBAC5B,UAAU,CAAC,WAAW,GAAG,KAAK,CAAC;YACjC,CAAC;YACD,IAAI,CAAC;gBACH,OAAO,MAAM,IAAI,CAAC,oBAAoB,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;YACzE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IACE,KAAK,YAAY,kBAAU;oBAC3B,KAAK,CAAC,IAAI,KAAK,2BAAmB,CAAC,oBAAoB,E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,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,UAAU,CAAC,KAAK,EAAE,CAAC;gBACnB,MAAM,IAAI,sBAAc,CAAC,iCAAiC,wCAAoB,KAAK,CAAC,CAAC;YACvF,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;IACH,CAAC;CACF;AAtED,8DAsEC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callback = void 0;
|
|
4
|
+
const azure_1 = require("../../../client-side-encryption/providers/azure");
|
|
5
|
+
const error_1 = require("../../../error");
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
/** Azure request headers. */
|
|
8
|
+
const AZURE_HEADERS = Object.freeze({ Metadata: 'true', Accept: 'application/json' });
|
|
9
|
+
/** Invalid endpoint result error. */
|
|
10
|
+
const ENDPOINT_RESULT_ERROR = 'Azure endpoint did not return a value with only access_token and expires_in properties';
|
|
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 azure.';
|
|
13
|
+
/**
|
|
14
|
+
* The callback function to be used in the automated callback workflow.
|
|
15
|
+
* @param params - The OIDC callback parameters.
|
|
16
|
+
* @returns The OIDC response.
|
|
17
|
+
*/
|
|
18
|
+
const callback = async (params) => {
|
|
19
|
+
const tokenAudience = params.tokenAudience;
|
|
20
|
+
const username = params.username;
|
|
21
|
+
if (!tokenAudience) {
|
|
22
|
+
throw new error_1.MongoAzureError(TOKEN_RESOURCE_MISSING_ERROR);
|
|
23
|
+
}
|
|
24
|
+
const response = await getAzureTokenData(tokenAudience, username);
|
|
25
|
+
if (!isEndpointResultValid(response)) {
|
|
26
|
+
throw new error_1.MongoAzureError(ENDPOINT_RESULT_ERROR);
|
|
27
|
+
}
|
|
28
|
+
return response;
|
|
29
|
+
};
|
|
30
|
+
exports.callback = callback;
|
|
31
|
+
/**
|
|
32
|
+
* Hit the Azure endpoint to get the token data.
|
|
33
|
+
*/
|
|
34
|
+
async function getAzureTokenData(tokenAudience, username) {
|
|
35
|
+
const url = new URL(azure_1.AZURE_BASE_URL);
|
|
36
|
+
(0, azure_1.addAzureParams)(url, tokenAudience, username);
|
|
37
|
+
const response = await (0, utils_1.get)(url, {
|
|
38
|
+
headers: AZURE_HEADERS
|
|
39
|
+
});
|
|
40
|
+
if (response.status !== 200) {
|
|
41
|
+
throw new error_1.MongoAzureError(`Status code ${response.status} returned from the Azure endpoint. Response body: ${response.body}`);
|
|
42
|
+
}
|
|
43
|
+
const result = JSON.parse(response.body);
|
|
44
|
+
return {
|
|
45
|
+
accessToken: result.access_token,
|
|
46
|
+
expiresInSeconds: Number(result.expires_in)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Determines if a result returned from the endpoint is valid.
|
|
51
|
+
* This means the result is not nullish, contains the access_token required field
|
|
52
|
+
* and the expires_in required field.
|
|
53
|
+
*/
|
|
54
|
+
function isEndpointResultValid(token) {
|
|
55
|
+
if (token == null || typeof token !== 'object')
|
|
56
|
+
return false;
|
|
57
|
+
return ('accessToken' in token &&
|
|
58
|
+
typeof token.accessToken === 'string' &&
|
|
59
|
+
'expiresInSeconds' in token &&
|
|
60
|
+
typeof token.expiresInSeconds === 'number');
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=azure_machine_workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure_machine_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts"],"names":[],"mappings":";;;AAAA,2EAAiG;AACjG,0CAAiD;AACjD,0CAAqC;AAGrC,6BAA6B;AAC7B,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,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KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY;QAChC,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;KAC5C,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB,CAC5B,KAAc;IAEd,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC7D,OAAO,CACL,aAAa,IAAI,KAAK;QACtB,OAAO,KAAK,CAAC,WAAW,KAAK,QAAQ;QACrC,kBAAkB,IAAI,KAAK;QAC3B,OAAO,KAAK,CAAC,gBAAgB,KAAK,QAAQ,CAC3C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CallbackWorkflow = exports.AUTOMATED_TIMEOUT_MS = exports.HUMAN_TIMEOUT_MS = void 0;
|
|
4
|
+
const promises_1 = require("timers/promises");
|
|
5
|
+
const error_1 = require("../../../error");
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const command_builders_1 = require("./command_builders");
|
|
8
|
+
/** 5 minutes in milliseconds */
|
|
9
|
+
exports.HUMAN_TIMEOUT_MS = 300000;
|
|
10
|
+
/** 1 minute in milliseconds */
|
|
11
|
+
exports.AUTOMATED_TIMEOUT_MS = 60000;
|
|
12
|
+
/** Properties allowed on results of callbacks. */
|
|
13
|
+
const RESULT_PROPERTIES = ['accessToken', 'expiresInSeconds', 'refreshToken'];
|
|
14
|
+
/** Error message when the callback result is invalid. */
|
|
15
|
+
const CALLBACK_RESULT_ERROR = 'User provided OIDC callbacks must return a valid object with an accessToken.';
|
|
16
|
+
/** The time to throttle callback calls. */
|
|
17
|
+
const THROTTLE_MS = 100;
|
|
18
|
+
/**
|
|
19
|
+
* OIDC implementation of a callback based workflow.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
class CallbackWorkflow {
|
|
23
|
+
/**
|
|
24
|
+
* Instantiate the callback workflow.
|
|
25
|
+
*/
|
|
26
|
+
constructor(cache, callback) {
|
|
27
|
+
this.cache = cache;
|
|
28
|
+
this.callback = this.withLock(callback);
|
|
29
|
+
this.lastExecutionTime = Date.now() - THROTTLE_MS;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the document to add for speculative authentication. This also needs
|
|
33
|
+
* to add a db field from the credentials source.
|
|
34
|
+
*/
|
|
35
|
+
async speculativeAuth(connection, credentials) {
|
|
36
|
+
// Check if the Client Cache has an access token.
|
|
37
|
+
// If it does, cache the access token in the Connection Cache and send a JwtStepRequest
|
|
38
|
+
// with the cached access token in the speculative authentication SASL payload.
|
|
39
|
+
if (this.cache.hasAccessToken) {
|
|
40
|
+
const accessToken = this.cache.getAccessToken();
|
|
41
|
+
connection.accessToken = accessToken;
|
|
42
|
+
const document = (0, command_builders_1.finishCommandDocument)(accessToken);
|
|
43
|
+
document.db = credentials.source;
|
|
44
|
+
return { speculativeAuthenticate: document };
|
|
45
|
+
}
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Reauthenticate the callback workflow. For this we invalidated the access token
|
|
50
|
+
* in the cache and run the authentication steps again. No initial handshake needs
|
|
51
|
+
* to be sent.
|
|
52
|
+
*/
|
|
53
|
+
async reauthenticate(connection, credentials) {
|
|
54
|
+
if (this.cache.hasAccessToken) {
|
|
55
|
+
// Reauthentication implies the token has expired.
|
|
56
|
+
if (connection.accessToken === this.cache.getAccessToken()) {
|
|
57
|
+
// If connection's access token is the same as the cache's, remove
|
|
58
|
+
// the token from the cache and connection.
|
|
59
|
+
this.cache.removeAccessToken();
|
|
60
|
+
delete connection.accessToken;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// If the connection's access token is different from the cache's, set
|
|
64
|
+
// the cache's token on the connection and do not remove from the
|
|
65
|
+
// cache.
|
|
66
|
+
connection.accessToken = this.cache.getAccessToken();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
await this.execute(connection, credentials);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Starts the callback authentication process. If there is a speculative
|
|
73
|
+
* authentication document from the initial handshake, then we will use that
|
|
74
|
+
* value to get the issuer, otherwise we will send the saslStart command.
|
|
75
|
+
*/
|
|
76
|
+
async startAuthentication(connection, credentials, response) {
|
|
77
|
+
let result;
|
|
78
|
+
if (response?.speculativeAuthenticate) {
|
|
79
|
+
result = response.speculativeAuthenticate;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
result = await connection.command((0, utils_1.ns)(credentials.source), (0, command_builders_1.startCommandDocument)(credentials), undefined);
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Finishes the callback authentication process.
|
|
88
|
+
*/
|
|
89
|
+
async finishAuthentication(connection, credentials, token, conversationId) {
|
|
90
|
+
await connection.command((0, utils_1.ns)(credentials.source), (0, command_builders_1.finishCommandDocument)(token, conversationId), undefined);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Executes the callback and validates the output.
|
|
94
|
+
*/
|
|
95
|
+
async executeAndValidateCallback(params) {
|
|
96
|
+
const result = await this.callback(params);
|
|
97
|
+
// Validate that the result returned by the callback is acceptable. If it is not
|
|
98
|
+
// we must clear the token result from the cache.
|
|
99
|
+
if (isCallbackResultInvalid(result)) {
|
|
100
|
+
throw new error_1.MongoMissingCredentialsError(CALLBACK_RESULT_ERROR);
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Ensure the callback is only executed one at a time and throttles the calls
|
|
106
|
+
* to every 100ms.
|
|
107
|
+
*/
|
|
108
|
+
withLock(callback) {
|
|
109
|
+
let lock = Promise.resolve();
|
|
110
|
+
return async (params) => {
|
|
111
|
+
// We do this to ensure that we would never return the result of the
|
|
112
|
+
// previous lock, only the current callback's value would get returned.
|
|
113
|
+
await lock;
|
|
114
|
+
lock = lock
|
|
115
|
+
.catch(() => null)
|
|
116
|
+
.then(async () => {
|
|
117
|
+
const difference = Date.now() - this.lastExecutionTime;
|
|
118
|
+
if (difference <= THROTTLE_MS) {
|
|
119
|
+
await (0, promises_1.setTimeout)(THROTTLE_MS - difference, { signal: params.timeoutContext });
|
|
120
|
+
}
|
|
121
|
+
this.lastExecutionTime = Date.now();
|
|
122
|
+
return await callback(params);
|
|
123
|
+
});
|
|
124
|
+
return await lock;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.CallbackWorkflow = CallbackWorkflow;
|
|
129
|
+
/**
|
|
130
|
+
* Determines if a result returned from a request or refresh callback
|
|
131
|
+
* function is invalid. This means the result is nullish, doesn't contain
|
|
132
|
+
* the accessToken required field, and does not contain extra fields.
|
|
133
|
+
*/
|
|
134
|
+
function isCallbackResultInvalid(tokenResult) {
|
|
135
|
+
if (tokenResult == null || typeof tokenResult !== 'object')
|
|
136
|
+
return true;
|
|
137
|
+
if (!('accessToken' in tokenResult))
|
|
138
|
+
return true;
|
|
139
|
+
return !Object.getOwnPropertyNames(tokenResult).every(prop => RESULT_PROPERTIES.includes(prop));
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=callback_workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/callback_workflow.ts"],"names":[],"mappings":";;;AAAA,8CAA6C;AAG7C,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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ineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.finishCommandDocument = finishCommandDocument;
|
|
4
|
+
exports.startCommandDocument = startCommandDocument;
|
|
5
|
+
const bson_1 = require("../../../bson");
|
|
6
|
+
const providers_1 = require("../providers");
|
|
7
|
+
/**
|
|
8
|
+
* Generate the finishing command document for authentication. Will be a
|
|
9
|
+
* saslStart or saslContinue depending on the presence of a conversation id.
|
|
10
|
+
*/
|
|
11
|
+
function finishCommandDocument(token, conversationId) {
|
|
12
|
+
if (conversationId != null) {
|
|
13
|
+
return {
|
|
14
|
+
saslContinue: 1,
|
|
15
|
+
conversationId: conversationId,
|
|
16
|
+
payload: new bson_1.Binary(bson_1.BSON.serialize({ jwt: token }))
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// saslContinue requires a conversationId in the command to be valid so in this
|
|
20
|
+
// case the server allows "step two" to actually be a saslStart with the token
|
|
21
|
+
// as the jwt since the use of the cached value has no correlating conversating
|
|
22
|
+
// on the particular connection.
|
|
23
|
+
return {
|
|
24
|
+
saslStart: 1,
|
|
25
|
+
mechanism: providers_1.AuthMechanism.MONGODB_OIDC,
|
|
26
|
+
payload: new bson_1.Binary(bson_1.BSON.serialize({ jwt: token }))
|
|
27
|
+
};
|
|
28
|
+
}
|
|
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
|
+
//# 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":";;AAmBA,sDAiBC;AAKD,oDAWC;AApDD,wCAA4D;AAE5D,4CAA6C;AAa7C;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,KAAa,EAAE,cAAuB;IAC1E,IAAI,cAAc,IAAI,IAAI,EAAE,CAAC;QAC3B,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;IACJ,CAAC;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;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,WAA6B;IAChE,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,CAAC,CAAC,GAAG,WAAW,CAAC,QAAQ,CAAC;IACnC,CAAC;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"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callback = void 0;
|
|
4
|
+
const error_1 = require("../../../error");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
/** GCP base URL. */
|
|
7
|
+
const GCP_BASE_URL = 'http://metadata/computeMetadata/v1/instance/service-accounts/default/identity';
|
|
8
|
+
/** GCP request headers. */
|
|
9
|
+
const GCP_HEADERS = Object.freeze({ 'Metadata-Flavor': 'Google' });
|
|
10
|
+
/** Error for when the token audience is missing in the environment. */
|
|
11
|
+
const TOKEN_RESOURCE_MISSING_ERROR = 'TOKEN_RESOURCE must be set in the auth mechanism properties when ENVIRONMENT is gcp.';
|
|
12
|
+
/**
|
|
13
|
+
* The callback function to be used in the automated callback workflow.
|
|
14
|
+
* @param params - The OIDC callback parameters.
|
|
15
|
+
* @returns The OIDC response.
|
|
16
|
+
*/
|
|
17
|
+
const callback = async (params) => {
|
|
18
|
+
const tokenAudience = params.tokenAudience;
|
|
19
|
+
if (!tokenAudience) {
|
|
20
|
+
throw new error_1.MongoGCPError(TOKEN_RESOURCE_MISSING_ERROR);
|
|
21
|
+
}
|
|
22
|
+
return await getGcpTokenData(tokenAudience);
|
|
23
|
+
};
|
|
24
|
+
exports.callback = callback;
|
|
25
|
+
/**
|
|
26
|
+
* Hit the GCP endpoint to get the token data.
|
|
27
|
+
*/
|
|
28
|
+
async function getGcpTokenData(tokenAudience) {
|
|
29
|
+
const url = new URL(GCP_BASE_URL);
|
|
30
|
+
url.searchParams.append('audience', tokenAudience);
|
|
31
|
+
const response = await (0, utils_1.get)(url, {
|
|
32
|
+
headers: GCP_HEADERS
|
|
33
|
+
});
|
|
34
|
+
if (response.status !== 200) {
|
|
35
|
+
throw new error_1.MongoGCPError(`Status code ${response.status} returned from the GCP endpoint. Response body: ${response.body}`);
|
|
36
|
+
}
|
|
37
|
+
return { accessToken: response.body };
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=gcp_machine_workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gcp_machine_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mong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+
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,wCAAqC;AACrC,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,CAAC;YAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;YAC1C,UAAU,CAAC,WAAW,GAAG,KAAK,CAAC;YAC/B,IAAI,CAAC;gBACH,OAAO,MAAM,IAAI,CAAC,oBAAoB,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;YACzE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IACE,KAAK,YAAY,kBAAU;oBAC3B,KAAK,CAAC,IAAI,KAAK,2BAAmB,CAAC,oBAAoB,EACvD,CAAC;oBACD,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC;oBAC/B,OAAO,UAAU,CAAC,WAAW,CAAC;oBAC9B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;gBACrD,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QACD,iDAAiD;QACjD,8FAA8F;QAC9F,yFAAyF;QACzF,6FAA6F;QAC7F,8FAA8F;QAC9F,iGAAiG;QACjG,sDAAsD;QACtD,IAAI,IAAI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E,CAAC;QAClB,CAAC;IACH,CAAC;CACF;AAzHD,sDAyHC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callback = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const process = require("process");
|
|
6
|
+
/** The fallback file name */
|
|
7
|
+
const FALLBACK_FILENAME = '/var/run/secrets/kubernetes.io/serviceaccount/token';
|
|
8
|
+
/** The azure environment variable for the file name. */
|
|
9
|
+
const AZURE_FILENAME = 'AZURE_FEDERATED_TOKEN_FILE';
|
|
10
|
+
/** The AWS environment variable for the file name. */
|
|
11
|
+
const AWS_FILENAME = 'AWS_WEB_IDENTITY_TOKEN_FILE';
|
|
12
|
+
/**
|
|
13
|
+
* The callback function to be used in the automated callback workflow.
|
|
14
|
+
* @param params - The OIDC callback parameters.
|
|
15
|
+
* @returns The OIDC response.
|
|
16
|
+
*/
|
|
17
|
+
const callback = async () => {
|
|
18
|
+
let filename;
|
|
19
|
+
if (process.env[AZURE_FILENAME]) {
|
|
20
|
+
filename = process.env[AZURE_FILENAME];
|
|
21
|
+
}
|
|
22
|
+
else if (process.env[AWS_FILENAME]) {
|
|
23
|
+
filename = process.env[AWS_FILENAME];
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
filename = FALLBACK_FILENAME;
|
|
27
|
+
}
|
|
28
|
+
const token = await (0, promises_1.readFile)(filename, 'utf8');
|
|
29
|
+
return { accessToken: token };
|
|
30
|
+
};
|
|
31
|
+
exports.callback = callback;
|
|
32
|
+
//# sourceMappingURL=k8s_machine_workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"k8s_machine_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,mCAAmC;AAInC,6BAA6B;AAC7B,MAAM,iBAAiB,GAAG,qDAAqD,CAAC;AAEhF,wDAAwD;AACxD,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,sDAAsD;AACtD,MAAM,YAAY,GAAG,6BAA6B,CAAC;AAEnD;;;;GAIG;AACI,MAAM,QAAQ,GAAyB,KAAK,IAA2B,EAAE;IAC9E,IAAI,QAAgB,CAAC;IACrB,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;QAChC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACzC,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;QACrC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,iBAAiB,CAAC;IAC/B,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,IAAA,mBAAQ,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC/C,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;AAChC,CAAC,CAAC;AAXW,QAAA,QAAQ,YAWnB"}
|
|
@@ -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,CAAC;YACtB,MAAM,IAAI,cAAc,CAAC,oDAAoD,CAAC,CAAC;QACjF,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,eAAe;QACb,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,MAAM,IAAI,cAAc,CAAC,oDAAoD,CAAC,CAAC;QACjF,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,cAAc,CAAC,oDAAoD,CAAC,CAAC;QACjF,CAAC;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,CAAC;YACZ,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACzB,CAAC;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,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callback = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const process = require("process");
|
|
6
|
+
const error_1 = require("../../../error");
|
|
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
|
+
* The callback function to be used in the automated callback workflow.
|
|
11
|
+
* @param params - The OIDC callback parameters.
|
|
12
|
+
* @returns The OIDC response.
|
|
13
|
+
*/
|
|
14
|
+
const callback = async () => {
|
|
15
|
+
const tokenFile = process.env.OIDC_TOKEN_FILE;
|
|
16
|
+
if (!tokenFile) {
|
|
17
|
+
throw new error_1.MongoAWSError(TOKEN_MISSING_ERROR);
|
|
18
|
+
}
|
|
19
|
+
const token = await fs.promises.readFile(tokenFile, 'utf8');
|
|
20
|
+
return { accessToken: token };
|
|
21
|
+
};
|
|
22
|
+
exports.callback = callback;
|
|
23
|
+
//# sourceMappingURL=token_machine_workflow.js.map
|