Skip to content

Commit a9cfc54

Browse files
authored
feat(connection-form): add option to prefer ID token over access token COMPASS-8107 (#6129)
1 parent 08e5c32 commit a9cfc54

File tree

6 files changed

+105
-31
lines changed

6 files changed

+105
-31
lines changed

package-lock.json

Lines changed: 49 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/atlas-service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"@mongodb-js/compass-utils": "^0.6.9",
8181
"@mongodb-js/devtools-connect": "^3.2.5",
8282
"@mongodb-js/devtools-proxy-support": "^0.3.5",
83-
"@mongodb-js/oidc-plugin": "^1.0.0",
83+
"@mongodb-js/oidc-plugin": "^1.1.1",
8484
"hadron-app-registry": "^9.2.2",
8585
"compass-preferences-model": "^2.26.0",
8686
"electron": "^29.4.5",

packages/atlas-service/src/main.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ describe('CompassAuthServiceMain', function () {
331331
} as any;
332332
await CompassAuthService.init(preferences, {} as any);
333333
CompassAuthService['config'] = defaultConfig;
334-
expect(getListenerCount(logger)).to.eq(27);
334+
expect(getListenerCount(logger)).to.eq(30);
335335
// We did all preparations, reset sinon history for easier assertions
336336
sandbox.resetHistory();
337337

packages/connection-form/src/components/advanced-options-tabs/authentication-tab/authentication-oidc.spec.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ describe('Authentication OIDC Connection Form', function () {
118118
});
119119
});
120120

121+
it('handles the Use ID token instead of Access Token checkbox', async function () {
122+
fireEvent.click(screen.getByText('Use ID token instead of Access Token'));
123+
await expectToConnectWith({
124+
connectionString:
125+
'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC&authSource=%24external',
126+
oidc: {
127+
passIdTokenAsAccessToken: true,
128+
},
129+
});
130+
});
131+
132+
it('handles the Use ID token instead of Access Token checkbox on and off', async function () {
133+
fireEvent.click(screen.getByText('Use ID token instead of Access Token'));
134+
fireEvent.click(screen.getByText('Use ID token instead of Access Token'));
135+
await expectToConnectWith({
136+
connectionString:
137+
'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC&authSource=%24external',
138+
oidc: {},
139+
});
140+
});
141+
121142
it('handles the Consider Target Endpoint Trusted checkbox', async function () {
122143
fireEvent.click(screen.getByText('Consider Target Endpoint Trusted'));
123144
await expectToConnectWith({

packages/connection-form/src/components/advanced-options-tabs/authentication-tab/authentication-oidc.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,38 @@ function AuthenticationOIDC({
121121
/>
122122
</FormFieldContainer>
123123

124+
<FormFieldContainer>
125+
<Checkbox
126+
onChange={({
127+
target: { checked },
128+
}: React.ChangeEvent<HTMLInputElement>) => {
129+
if (checked) {
130+
return handleFieldChanged('passIdTokenAsAccessToken', true);
131+
}
132+
133+
return handleFieldChanged(
134+
'passIdTokenAsAccessToken',
135+
undefined
136+
);
137+
}}
138+
data-testid="oidc-pass-id-token-as-access-token"
139+
id="oidc-pass-id-token-as-access-token"
140+
label={
141+
<>
142+
<Label htmlFor="oidc-pass-id-token-as-access-token">
143+
Use ID token instead of Access Token
144+
</Label>
145+
<Description>
146+
Use ID tokens instead of access tokens to work around
147+
misconfigured or broken identity providers. This will only
148+
work if the server is configured correspondingly.
149+
</Description>
150+
</>
151+
}
152+
checked={!!connectionOptions.oidc?.passIdTokenAsAccessToken}
153+
/>
154+
</FormFieldContainer>
155+
124156
{showOIDCDeviceAuthFlow && (
125157
<FormFieldContainer>
126158
<Checkbox

packages/data-service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"@mongodb-js/devtools-docker-test-envs": "^1.3.2",
6868
"@mongodb-js/eslint-config-compass": "^1.1.4",
6969
"@mongodb-js/mocha-config-compass": "^1.3.10",
70-
"@mongodb-js/oidc-plugin": "^1.0.0",
70+
"@mongodb-js/oidc-plugin": "^1.1.1",
7171
"@mongodb-js/prettier-config-compass": "^1.0.2",
7272
"@mongodb-js/tsconfig-compass": "^1.0.4",
7373
"@types/lodash": "^4.14.188",

0 commit comments

Comments
 (0)