Skip to content

Commit be5803f

Browse files
authored
Revert "feat!(devtools-connect): update oidc MONGOSH-1790 (#347)"
This reverts commit bd7ed21.
1 parent 9f798d6 commit be5803f

File tree

4 files changed

+105
-49
lines changed

4 files changed

+105
-49
lines changed

package-lock.json

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

packages/devtools-connect/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454
"system-ca": "^1.0.2"
5555
},
5656
"peerDependencies": {
57-
"@mongodb-js/oidc-plugin": "^1.0.0",
57+
"@mongodb-js/oidc-plugin": "^0.4.0",
5858
"mongodb": "^5.8.1 || ^6.0.0",
5959
"mongodb-log-writer": "^1.4.2"
6060
},
6161
"devDependencies": {
62-
"@mongodb-js/oidc-plugin": "^1.0.0",
62+
"@mongodb-js/oidc-plugin": "^0.4.0",
6363
"@mongodb-js/saslprep": "^1.1.7",
6464
"@types/lodash.merge": "^4.6.7",
6565
"@types/mocha": "^9.0.0",

packages/devtools-connect/src/ipc-rpc-state-share.spec.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,65 +102,71 @@ describe('IPC RPC state sharing', function () {
102102

103103
describe('StateShareServer/StateShareClient', function () {
104104
let fakeState: DevtoolsConnectionState;
105-
let callback: sinon.SinonStub;
105+
let request: sinon.SinonStub;
106+
let refresh: sinon.SinonStub;
106107
let server: StateShareServer;
107108
let client: StateShareClient;
108109

109110
beforeEach(function () {
110-
callback = sinon.stub();
111+
request = sinon.stub();
112+
refresh = sinon.stub();
111113
fakeState = {
112114
productName: 'MongoDB Something',
113115
oidcPlugin: {
114116
mongoClientOptions: {
115117
authMechanismProperties: {
116-
OIDC_HUMAN_CALLBACK: callback,
118+
REFRESH_TOKEN_CALLBACK: refresh,
119+
REQUEST_TOKEN_CALLBACK: request,
117120
},
118121
},
119122
},
120123
} as unknown as DevtoolsConnectionState;
124+
request.resolves({ accessToken: 'req-accesstoken' });
125+
refresh.resolves({ accessToken: 'ref-accesstoken' });
121126
});
122127

123128
afterEach(async function () {
124129
await server.close();
125130
});
126131

127132
it('can be used to share OIDC state', async function () {
128-
callback.resolves({ accessToken: 'req-accesstoken' });
129133
server = await StateShareServer.create(fakeState);
130134
client = new StateShareClient(server.handle);
131135
const result =
132-
await client.oidcPlugin.mongoClientOptions.authMechanismProperties.OIDC_HUMAN_CALLBACK(
136+
await client.oidcPlugin.mongoClientOptions.authMechanismProperties.REQUEST_TOKEN_CALLBACK(
133137
{
134-
idpInfo: {
135-
issuer: 'http://localhost/',
136-
clientId: 'clientId',
137-
},
138-
version: 1,
138+
issuer: 'http://localhost/',
139+
clientId: 'clientId',
140+
},
141+
{
142+
version: 0,
139143
}
140144
);
141145
expect(result).to.deep.equal({ accessToken: 'req-accesstoken' });
142146
});
143147

144148
it('supports timeoutContext', async function () {
145-
callback.callsFake((params: { timeoutContext: AbortSignal }) => {
146-
return new Promise((resolve, reject) =>
147-
params.timeoutContext.addEventListener('abort', () =>
148-
reject(new Error('aborted'))
149-
)
150-
);
151-
});
149+
refresh.callsFake(
150+
(_idpInfo: unknown, ctx: { timeoutContext: AbortSignal }) => {
151+
return new Promise((resolve, reject) =>
152+
ctx.timeoutContext.addEventListener('abort', () =>
153+
reject(new Error('aborted'))
154+
)
155+
);
156+
}
157+
);
152158
server = await StateShareServer.create(fakeState);
153159
client = new StateShareClient(server.handle);
154160

155161
const abortController = new AbortController();
156162
const result =
157-
client.oidcPlugin.mongoClientOptions.authMechanismProperties.OIDC_HUMAN_CALLBACK(
163+
client.oidcPlugin.mongoClientOptions.authMechanismProperties.REFRESH_TOKEN_CALLBACK(
158164
{
159-
idpInfo: {
160-
issuer: 'http://localhost/',
161-
clientId: 'clientId',
162-
},
163-
version: 1,
165+
issuer: 'http://localhost/',
166+
clientId: 'clientId',
167+
},
168+
{
169+
version: 0,
164170
timeoutContext: abortController.signal,
165171
}
166172
);

packages/devtools-connect/src/ipc-rpc-state-share.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type {
22
MongoDBOIDCPlugin,
3+
IdPServerInfo,
34
IdPServerResponse,
4-
OIDCCallbackParams,
5+
OIDCCallbackContext,
56
} from '@mongodb-js/oidc-plugin';
67
import type { DevtoolsConnectionState } from './connect';
78
import { createServer as createHTTPServer, request } from 'http';
@@ -224,21 +225,26 @@ export class StateShareServer extends RpcServer {
224225

225226
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
226227
protected async handleRpc(content: any): Promise<Record<string, unknown>> {
228+
const oidcCallbacks =
229+
this.state.oidcPlugin.mongoClientOptions.authMechanismProperties;
230+
let oidcMethod: keyof typeof oidcCallbacks;
227231
switch (content.method) {
228232
case 'oidc:_abort':
229233
this.abortContexts.get(content.timeoutContextId)?.abort();
230234
return {};
231-
case 'oidc:OIDC_HUMAN_CALLBACK': {
235+
case 'oidc:REQUEST_TOKEN_CALLBACK':
236+
oidcMethod = 'REQUEST_TOKEN_CALLBACK';
237+
// fallthrough
238+
case 'oidc:REFRESH_TOKEN_CALLBACK': {
239+
oidcMethod ??= 'REFRESH_TOKEN_CALLBACK';
240+
232241
const abortController = new AbortController();
233242
this.abortContexts.set(content.timeoutContextId, abortController);
234243
try {
235-
const result =
236-
await this.state.oidcPlugin.mongoClientOptions.authMechanismProperties.OIDC_HUMAN_CALLBACK(
237-
{
238-
...content.callbackParams,
239-
timeoutContext: abortController.signal,
240-
}
241-
);
244+
const result = await oidcCallbacks[oidcMethod](content.info, {
245+
...content.context,
246+
timeoutContext: abortController.signal,
247+
});
242248
return { result };
243249
} finally {
244250
this.abortContexts.delete(content.timeoutContextId);
@@ -269,9 +275,13 @@ export class StateShareClient extends RpcClient {
269275
logger: new EventEmitter(),
270276
mongoClientOptions: {
271277
authMechanismProperties: {
272-
OIDC_HUMAN_CALLBACK: this._oidcCallback.bind(
278+
REQUEST_TOKEN_CALLBACK: this._oidcCallback.bind(
279+
this,
280+
'oidc:REQUEST_TOKEN_CALLBACK'
281+
),
282+
REFRESH_TOKEN_CALLBACK: this._oidcCallback.bind(
273283
this,
274-
'oidc:OIDC_HUMAN_CALLBACK'
284+
'oidc:REFRESH_TOKEN_CALLBACK'
275285
),
276286
},
277287
},
@@ -280,12 +290,13 @@ export class StateShareClient extends RpcClient {
280290

281291
private async _oidcCallback(
282292
method: string,
283-
params: OIDCCallbackParams
293+
info: IdPServerInfo,
294+
_context: OIDCCallbackContext
284295
): Promise<IdPServerResponse> {
285296
const timeoutContextId = (await promisify(crypto.randomBytes)(16)).toString(
286297
'base64'
287298
);
288-
const { timeoutContext, ...callbackParams } = params;
299+
const { timeoutContext, ...context } = _context;
289300
const abort = async () => {
290301
await this.makeRpcCall({
291302
method: 'oidc:_abort',
@@ -297,7 +308,8 @@ export class StateShareClient extends RpcClient {
297308
const { result } = await this.makeRpcCall({
298309
method,
299310
timeoutContextId,
300-
callbackParams,
311+
context,
312+
info,
301313
});
302314
return result as IdPServerResponse;
303315
} finally {

0 commit comments

Comments
 (0)