Skip to content

Commit cd95065

Browse files
authored
feat: add OIDC auth support, enable in new form VSCODE-354 (#630)
1 parent 4e2cbeb commit cd95065

File tree

13 files changed

+244
-75
lines changed

13 files changed

+244
-75
lines changed

.github/workflows/actions/test-and-build/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ runs:
7676

7777
- name: Build .vsix
7878
env:
79-
NODE_OPTIONS: "--require ./scripts/no-npm-list-fail.js"
79+
NODE_OPTIONS: "--require ./scripts/no-npm-list-fail.js --max_old_space_size=4096"
8080
# NOTE: --githubBranch is "The GitHub branch used to infer relative links in README.md."
8181
run: |
8282
npx vsce package --githubBranch main

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ If you use Terraform to manage your infrastructure, MongoDB for VS Code helps yo
8080
| `mdb.defaultLimit` | The number of documents to fetch when viewing documents from a collection. | `10` |
8181
| `mdb.confirmRunAll` | Show a confirmation message before running commands in a playground. | `true` |
8282
| `mdb.confirmDeleteDocument` | Show a confirmation message before deleting a document in the tree view. | `true` |
83+
| `mdb.persistOIDCTokens` | Remain logged in when using the MONGODB-OIDC authentication mechanism for MongoDB server connection. Access tokens are encrypted using the system keychain before being stored. | `true` |
8384
| `mdb.excludeFromPlaygroundsSearch` | Exclude files and folders while searching for playground files in the current workspace. | Refer to [`package.json`](https://github.com/mongodb-js/vscode/blob/7b10092db4c8c10c4aa9c45b443c8ed3d5f37d5c/package.json) |
8485
| `mdb.connectionSaving.` `hideOptionToChooseWhereToSaveNewConnections` | When a connection is added, a prompt is shown that let's the user decide where the new connection should be saved. When this setting is checked, the prompt is not shown and the default connection saving location setting is used. | `true` |
8586
| `mdb.connectionSaving.` `defaultConnectionSavingLocation` | When the setting that hides the option to choose where to save new connections is checked, this setting sets if and where new connections are saved. | `Global` |

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,11 @@
932932
"default": true,
933933
"description": "Show a confirmation message before deleting a document from the tree view."
934934
},
935+
"mdb.persistOIDCTokens": {
936+
"type": "boolean",
937+
"default": true,
938+
"description": "Remain logged in when using the MONGODB-OIDC authentication mechanism for MongoDB server connection. Access tokens are encrypted using the system keychain before being stored."
939+
},
935940
"mdb.sendTelemetry": {
936941
"type": "boolean",
937942
"default": true,
@@ -991,6 +996,7 @@
991996
"classnames": "^2.3.2",
992997
"debug": "^4.3.4",
993998
"dotenv": "^16.3.1",
999+
"lodash": "^4.17.21",
9941000
"micromatch": "^4.0.5",
9951001
"mongodb": "^6.0.0",
9961002
"mongodb-build-info": "^1.6.2",

scripts/check-vsix-size.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const vsixFileName = path.resolve(
1212
);
1313
const size = fs.statSync(vsixFileName).size;
1414

15-
const maxSize = 8 * 1000000; // 8 MB
15+
const maxSize = 8_500_000; // 8.5 MB
1616

1717
if (size >= maxSize) {
1818
throw new Error(

src/commands/launchMongoShell.ts

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,47 @@ import * as vscode from 'vscode';
22

33
import type ConnectionController from '../connectionController';
44

5-
const launchMongoDBShellWithEnv = (
6-
shellCommand: string,
7-
mdbConnectionString: string,
8-
envVariableString: string
9-
) => {
5+
const launchMongoDBShellWithEnv = ({
6+
shellCommand,
7+
mdbConnectionString,
8+
envVariableString,
9+
parentHandle,
10+
}: {
11+
shellCommand: string;
12+
mdbConnectionString: string;
13+
envVariableString: string;
14+
parentHandle?: string;
15+
}) => {
1016
const mongoDBShell = vscode.window.createTerminal({
1117
name: 'MongoDB Shell',
1218
env: {
1319
MDB_CONNECTION_STRING: mdbConnectionString,
20+
...(parentHandle
21+
? {
22+
MONGOSH_OIDC_PARENT_HANDLE: parentHandle, // For OIDC to share the state and avoid extra logins.
23+
}
24+
: {}),
1425
},
1526
});
1627

1728
mongoDBShell.sendText(`${shellCommand} ${envVariableString};`);
1829
mongoDBShell.show();
1930
};
2031

21-
const launchMongoDBShellOnPowershell = (
22-
shellCommand: string,
23-
mdbConnectionString: string
24-
): void => {
25-
launchMongoDBShellWithEnv(
26-
shellCommand,
27-
mdbConnectionString,
28-
'$Env:MDB_CONNECTION_STRING'
29-
);
32+
const getPowershellEnvString = () => {
33+
return '$Env:MDB_CONNECTION_STRING';
3034
};
3135

32-
const launchMongoDBShellOnCmd = (
33-
shellCommand: string,
34-
mdbConnectionString: string
35-
): void => {
36-
launchMongoDBShellWithEnv(
37-
shellCommand,
38-
mdbConnectionString,
39-
'%MDB_CONNECTION_STRING%'
40-
);
36+
const getCmdEnvString = () => {
37+
return '%MDB_CONNECTION_STRING%';
4138
};
4239

43-
const launchMongoDBShellOnGitBash = (
44-
shellCommand: string,
45-
mdbConnectionString: string
46-
): void => {
47-
launchMongoDBShellWithEnv(
48-
shellCommand,
49-
mdbConnectionString,
50-
'$MDB_CONNECTION_STRING'
51-
);
40+
const getGitBashEnvString = () => {
41+
return '$MDB_CONNECTION_STRING';
5242
};
5343

54-
const launchMongoDBShellOnBash = (
55-
shellCommand: string,
56-
mdbConnectionString: string
57-
): void => {
58-
launchMongoDBShellWithEnv(
59-
shellCommand,
60-
mdbConnectionString,
61-
'$MDB_CONNECTION_STRING'
62-
);
44+
const getBashEnvString = () => {
45+
return '$MDB_CONNECTION_STRING';
6346
};
6447

6548
const openMongoDBShell = (
@@ -94,19 +77,31 @@ const openMongoDBShell = (
9477
}
9578

9679
const mdbConnectionString = connectionController.getActiveConnectionString();
80+
const parentHandle =
81+
connectionController.getMongoClientConnectionOptions()?.options
82+
.parentHandle;
83+
84+
let envVariableString = '';
9785

9886
if (userShell.includes('powershell.exe')) {
99-
launchMongoDBShellOnPowershell(shellCommand, mdbConnectionString);
87+
envVariableString = getPowershellEnvString();
10088
} else if (userShell.includes('cmd.exe')) {
101-
launchMongoDBShellOnCmd(shellCommand, mdbConnectionString);
89+
envVariableString = getCmdEnvString();
10290
} else if (userShell.toLocaleLowerCase().includes('git\\bin\\bash.exe')) {
103-
launchMongoDBShellOnGitBash(shellCommand, mdbConnectionString);
91+
envVariableString = getGitBashEnvString();
10492
} else {
10593
// Assume it's a bash environment. This may fail on certain
10694
// shells but should cover most cases.
107-
launchMongoDBShellOnBash(shellCommand, mdbConnectionString);
95+
envVariableString = getBashEnvString();
10896
}
10997

98+
launchMongoDBShellWithEnv({
99+
shellCommand,
100+
mdbConnectionString,
101+
parentHandle,
102+
envVariableString,
103+
});
104+
110105
return Promise.resolve(true);
111106
};
112107

0 commit comments

Comments
 (0)