MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / createClient

Function createClient

packages/core/sdk/src/oauth-service.ts:526–593  ·  view source on GitHub ↗
(
    input: CreateOAuthClientInput,
  )

Source from the content-addressed store, hash-verified

524 // createClient — write the oauth_client row.
525 // -----------------------------------------------------------------------
526 const createClient = (
527 input: CreateOAuthClientInput,
528 ): Effect.Effect<OAuthClientSlug, StorageFailure> =>
529 Effect.gen(function* () {
530 yield* validateClientEndpoints(input, deps.endpointUrlPolicy);
531 const keys = yield* Effect.try({
532 try: () => deps.ownedKeys(input.owner),
533 catch: (cause) =>
534 new StorageError({
535 message: "Cannot write oauth_client for owner without a subject",
536 cause,
537 }),
538 });
539 const now = new Date();
540
541 // Store the secret out-of-band in the default writable provider; the row
542 // keeps only its item id. A public/PKCE client (empty secret) stores null
543 // — there is no plaintext column to fall back to (the schema dropped it).
544 let clientSecretItemIdValue: string | null = null;
545 if (input.clientSecret.length > 0) {
546 const provider = deps.defaultWritableProvider();
547 if (!provider || !provider.set) {
548 return yield* new StorageError({
549 message:
550 "No default writable credential provider is registered to store the OAuth client secret.",
551 cause: undefined,
552 });
553 }
554 clientSecretItemIdValue = clientSecretItemId(input.owner, input.slug);
555 yield* provider.set(ProviderItemId.make(clientSecretItemIdValue), input.clientSecret);
556 }
557
558 yield* deps.fuma
559 .use("oauth_client.deleteExisting", (db) =>
560 looseDb(db).deleteMany("oauth_client", {
561 where: (b: any) =>
562 b.and(b("owner", "=", input.owner), b("slug", "=", String(input.slug))),
563 }),
564 )
565 .pipe(Effect.catch(() => Effect.void));
566 yield* deps.fuma.use("oauth_client.create", (db) =>
567 looseDb(db).create("oauth_client", {
568 tenant: keys.tenant,
569 owner: keys.owner,
570 subject: keys.subject,
571 slug: String(input.slug),
572 authorization_url: input.authorizationUrl,
573 token_url: input.tokenUrl,
574 grant: input.grant,
575 client_id: input.clientId,
576 client_secret_item_id: clientSecretItemIdValue,
577 resource: input.resource ?? null,
578 origin_kind: input.origin?.kind ?? "manual",
579 // Recorded intent, kept for BOTH origins: a manual app registered from
580 // an integration's dialog stamps its integration so the picker can
581 // match it exactly, the same way a DCR client records the integration
582 // that requested it.
583 origin_integration:

Callers 9

createSqliteTestFumaDbFunction · 0.70
registerDynamicClientFunction · 0.70
createFunction · 0.50
openOwnershipLockClientFunction · 0.50
openLocalLibsqlFunction · 0.50
createSqliteExecutorDbFunction · 0.50

Calls 5

canonicalIssuerUrlFunction · 0.90
validateClientEndpointsFunction · 0.85
clientSecretItemIdFunction · 0.85
looseDbFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected