Skip to content

Commit a6ad6cd

Browse files
committed
feat(NODE-5191): update oidc objects
1 parent ad15881 commit a6ad6cd

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

src/cmap/auth/mongo_credentials.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export interface AuthMechanismProperties extends Document {
4343
REFRESH_TOKEN_CALLBACK?: OIDCRefreshFunction;
4444
/** @experimental */
4545
PROVIDER_NAME?: 'aws';
46+
/** @experimental */
47+
ALLOWED_HOSTS?: string[];
4648
}
4749

4850
/** @public */

src/cmap/auth/mongodb_oidc.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ import type { Workflow } from './mongodb_oidc/workflow';
1111
* @experimental
1212
*/
1313
export interface OIDCMechanismServerStep1 {
14-
authorizationEndpoint?: string;
15-
tokenEndpoint?: string;
16-
deviceAuthorizationEndpoint?: string;
14+
issuer?: string;
1715
clientId: string;
18-
clientSecret?: string;
1916
requestScopes?: string[];
2017
}
2118

@@ -29,25 +26,33 @@ export interface OIDCRequestTokenResult {
2926
refreshToken?: string;
3027
}
3128

29+
/**
30+
* @public
31+
* @experimental
32+
*/
33+
export interface OIDCClientInfo {
34+
principalName: string;
35+
timeoutSeconds?: number;
36+
timeoutContext?: AbortSignal;
37+
}
38+
3239
/**
3340
* @public
3441
* @experimental
3542
*/
3643
export type OIDCRequestFunction = (
37-
principalName: string,
38-
serverResult: OIDCMechanismServerStep1,
39-
timeout: AbortSignal | number
44+
clientInfo: OIDCClientInfo,
45+
serverInfo: OIDCMechanismServerStep1
4046
) => Promise<OIDCRequestTokenResult>;
4147

4248
/**
4349
* @public
4450
* @experimental
4551
*/
4652
export type OIDCRefreshFunction = (
47-
principalName: string,
48-
serverResult: OIDCMechanismServerStep1,
49-
result: OIDCRequestTokenResult,
50-
timeout: AbortSignal | number
53+
clientInfo: OIDCClientInfo,
54+
serverInfo: OIDCMechanismServerStep1,
55+
tokenResult: OIDCRequestTokenResult
5156
) => Promise<OIDCRequestTokenResult>;
5257

5358
type ProviderName = 'aws' | 'callback';

src/cmap/auth/mongodb_oidc/callback_workflow.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { AuthMechanism } from '../providers';
99
import { TokenEntryCache } from './token_entry_cache';
1010
import type { Workflow } from './workflow';
1111

12-
/* 5 minutes in milliseconds */
13-
const TIMEOUT_MS = 300000;
12+
/* 5 minutes in seconds */
13+
const TIMEOUT_S = 300;
1414

1515
/**
1616
* OIDC implementation of a callback based workflow.
@@ -134,12 +134,8 @@ export class CallbackWorkflow implements Workflow {
134134
const refresh = credentials.mechanismProperties.REFRESH_TOKEN_CALLBACK;
135135
// If a refresh callback exists, use it. Otherwise use the request callback.
136136
if (refresh) {
137-
const result: OIDCRequestTokenResult = await refresh(
138-
credentials.username,
139-
stepOneResult,
140-
tokenResult,
141-
TIMEOUT_MS
142-
);
137+
const clientInfo = { principalName: credentials.username, timeoutSeconds: TIMEOUT_S };
138+
const result: OIDCRequestTokenResult = await refresh(clientInfo, stepOneResult, tokenResult);
143139
// Validate the result.
144140
if (!result || !result.accessToken) {
145141
throw new MongoMissingCredentialsError(
@@ -182,7 +178,8 @@ export class CallbackWorkflow implements Workflow {
182178
'Auth mechanism property REQUEST_TOKEN_CALLBACK is required.'
183179
);
184180
}
185-
const tokenResult = await request(credentials.username, stepOneResult, TIMEOUT_MS);
181+
const clientInfo = { principalName: credentials.username, timeoutSeconds: TIMEOUT_S };
182+
const tokenResult = await request(clientInfo, stepOneResult);
186183
// Validate the result.
187184
if (!tokenResult || !tokenResult.accessToken) {
188185
throw new MongoMissingCredentialsError(

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export type {
204204
MongoCredentialsOptions
205205
} from './cmap/auth/mongo_credentials';
206206
export type {
207+
OIDCClientInfo,
207208
OIDCMechanismServerStep1,
208209
OIDCRefreshFunction,
209210
OIDCRequestFunction,

0 commit comments

Comments
 (0)