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

Function createClient

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

Source from the content-addressed store, hash-verified

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