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

Function createClient

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

Source from the content-addressed store, hash-verified

594 // createClient — write the oauth_client row.
595 // -----------------------------------------------------------------------
596 const createClient = (
597 input: CreateOAuthClientInput,
598 ): Effect.Effect<OAuthClientSlug, StorageFailure> =>
599 Effect.gen(function* () {
600 yield* validateClientEndpoints(input, deps.endpointUrlPolicy);
601 const keys = yield* Effect.try({
602 try: () => deps.ownedKeys(input.owner),
603 catch: (cause) =>
604 new StorageError({
605 message: "Cannot write oauth_client for owner without a subject",
606 cause,
607 }),
608 });
609 const now = new Date();
610
611 // Store the secret out-of-band in the default writable provider; the row
612 // keeps only its item id. A public/PKCE client (empty secret) stores null
613 // — there is no plaintext column to fall back to (the schema dropped it).
614 let clientSecretItemIdValue: string | null = null;
615 if (input.clientSecret.length > 0) {
616 const provider = deps.defaultWritableProvider();
617 if (!provider || !provider.set) {
618 return yield* new StorageError({
619 message:
620 "No default writable credential provider is registered to store the OAuth client secret.",
621 cause: undefined,
622 });
623 }
624 clientSecretItemIdValue = clientSecretItemId(input.owner, input.slug);
625 yield* provider.set(ProviderItemId.make(clientSecretItemIdValue), input.clientSecret);
626 }
627
628 yield* deps.fuma
629 .use("oauth_client.deleteExisting", (db) =>
630 looseDb(db).deleteMany("oauth_client", {
631 where: (b: any) =>
632 b.and(b("owner", "=", input.owner), b("slug", "=", String(input.slug))),
633 }),
634 )
635 .pipe(Effect.catch(() => Effect.void));
636 yield* deps.fuma.use("oauth_client.create", (db) =>
637 looseDb(db).create("oauth_client", {
638 tenant: keys.tenant,
639 owner: keys.owner,
640 subject: keys.subject,
641 slug: String(input.slug),
642 authorization_url: input.authorizationUrl,
643 token_url: input.tokenUrl,
644 grant: input.grant,
645 client_id: input.clientId,
646 client_secret_item_id: clientSecretItemIdValue,
647 resource: input.resource ?? null,
648 origin_kind: input.origin?.kind ?? "manual",
649 // Recorded intent, kept for BOTH origins: a manual app registered from
650 // an integration's dialog stamps its integration so the picker can
651 // match it exactly, the same way a DCR client records the integration
652 // that requested it.
653 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