@q32/core 0.1.19 → 0.1.21

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/src/oauth.ts CHANGED
@@ -122,6 +122,9 @@ export type McpOAuthRepositoryOptions = {
122
122
  tokenEndpointAuthMethod?: string;
123
123
  subjectColumns?: McpOAuthSubjectColumn[];
124
124
  refreshRotationColumns?: boolean;
125
+ createClientId?: () => string;
126
+ createAuthorizationCodeId?: () => string;
127
+ createTokenId?: () => string;
125
128
  };
126
129
 
127
130
  export type McpAuthorizationCodeRow = {
@@ -292,7 +295,12 @@ export class GitHubOAuthClient {
292
295
  }
293
296
 
294
297
  export class McpOAuthRepository {
295
- private readonly options: Required<Pick<McpOAuthRepositoryOptions, "defaultScope" | "tokenEndpointAuthMethod" | "subjectColumns" | "refreshRotationColumns">>;
298
+ private readonly options: Required<
299
+ Pick<
300
+ McpOAuthRepositoryOptions,
301
+ "defaultScope" | "tokenEndpointAuthMethod" | "subjectColumns" | "refreshRotationColumns" | "createClientId" | "createAuthorizationCodeId" | "createTokenId"
302
+ >
303
+ >;
296
304
 
297
305
  constructor(
298
306
  private readonly db: D1DatabaseLike,
@@ -303,6 +311,9 @@ export class McpOAuthRepository {
303
311
  tokenEndpointAuthMethod: options.tokenEndpointAuthMethod ?? "none",
304
312
  subjectColumns: options.subjectColumns ?? DEFAULT_MCP_SUBJECT_COLUMNS,
305
313
  refreshRotationColumns: options.refreshRotationColumns ?? false,
314
+ createClientId: options.createClientId ?? (() => createId("mcpcli")),
315
+ createAuthorizationCodeId: options.createAuthorizationCodeId ?? (() => createId("mcpac")),
316
+ createTokenId: options.createTokenId ?? (() => createId("mcptok")),
306
317
  };
307
318
  }
308
319
 
@@ -341,7 +352,7 @@ export class McpOAuthRepository {
341
352
  }
342
353
 
343
354
  async registerClient(client: OAuthClientRegistration): Promise<OAuthClientInformation> {
344
- const clientId = createId("mcpcli");
355
+ const clientId = this.options.createClientId();
345
356
  const clientIdIssuedAt = nowEpochSeconds();
346
357
  await this.db
347
358
  .prepare(
@@ -424,7 +435,7 @@ export class McpOAuthRepository {
424
435
  `,
425
436
  )
426
437
  .bind(
427
- createId("mcpac"),
438
+ this.options.createAuthorizationCodeId(),
428
439
  await sha256Hex(input.code),
429
440
  input.clientId,
430
441
  ...subjectValues,
@@ -487,7 +498,7 @@ export class McpOAuthRepository {
487
498
  }): Promise<string> {
488
499
  const subjectColumns = this.options.subjectColumns.map((column) => quoteIdentifier(column.column));
489
500
  const subjectValues = this.options.subjectColumns.map((column) => requiredSubject(input.subject, column.field));
490
- const tokenId = createId("mcptok");
501
+ const tokenId = this.options.createTokenId();
491
502
  await this.db
492
503
  .prepare(
493
504
  `