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

Function createClient

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

Source from the content-addressed store, hash-verified

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