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

Function registerDynamicClient

packages/core/sdk/src/oauth-service.ts:870–948  ·  view source on GitHub ↗
(
    input: RegisterDynamicClientInput,
  )

Source from the content-addressed store, hash-verified

868 });
869
870 const registerDynamicClient = (
871 input: RegisterDynamicClientInput,
872 ): Effect.Effect<OAuthClientSlug, OAuthRegisterDynamicError | StorageFailure> =>
873 Effect.gen(function* () {
874 const issuer = canonicalDcrIssuer(input.issuer, input.registrationEndpoint);
875 // Resolved before the reuse decision: a persisted client registered with
876 // a DIFFERENT callback must not be reused (strict servers 400 the
877 // authorize request), so the reuse lookup compares against this value.
878 const flowRedirectUri = input.redirectUri ?? redirectUri ?? null;
879 const reuse = yield* decideDcrClientReuse(input, issuer, flowRedirectUri);
880 if (reuse.existingSlug !== null) return reuse.existingSlug;
881
882 const slug = reuse.registrationSlug;
883 // DCR registers our callback as the client's redirect_uri — fail loudly
884 // if the executor has none rather than registering a localhost URL.
885 if (flowRedirectUri == null) {
886 return yield* new OAuthRegisterDynamicError({
887 message: REDIRECT_URI_REQUIRED_MESSAGE,
888 });
889 }
890 const authMethod = pickDcrAuthMethod(input.tokenEndpointAuthMethodsSupported);
891 const information = yield* registerDynamicClientDcr(
892 {
893 registrationEndpoint: input.registrationEndpoint,
894 metadata: {
895 client_name: input.clientName,
896 redirect_uris: [flowRedirectUri],
897 grant_types: ["authorization_code", "refresh_token"],
898 response_types: ["code"],
899 token_endpoint_auth_method: authMethod,
900 scope: input.scopes.length > 0 ? input.scopes.join(" ") : undefined,
901 },
902 },
903 { httpClientLayer, endpointUrlPolicy: deps.endpointUrlPolicy },
904 ).pipe(
905 Effect.mapError((cause) => {
906 // Some authorization servers (Vercel, and others that follow RFC 8252
907 // strictly) reject anonymous Dynamic Client Registration unless the
908 // redirect URI is loopback (http://localhost or http://127.0.0.1).
909 // Executor registers its browser origin, so any hosted, tailnet, or
910 // LAN origin trips `invalid_redirect_uri`. Turn that opaque RFC code
911 // into guidance the user can act on instead of the raw error.
912 // oxlint-disable-next-line executor/no-unknown-error-message -- boundary: OAuthDiscoveryError carries a typed `message`
913 const rawMessage = cause.message;
914 const message =
915 cause.error === "invalid_redirect_uri" && !isLoopbackHttpUrl(flowRedirectUri)
916 ? `Automatic OAuth setup failed: this server only approves loopback redirect ` +
917 `URLs (http://localhost or http://127.0.0.1) for automatic registration, but ` +
918 `Executor is using ${flowRedirectUri}. Register an OAuth app manually with that ` +
919 `redirect URL approved by the server, or run Executor on http://localhost.`
920 : `Dynamic Client Registration failed: ${rawMessage}`;
921 return new OAuthRegisterDynamicError({ message });
922 }),
923 );
924
925 // Persist the minted client. DCR-minted public clients have no secret; we
926 // store "" so the PKCE-only token exchange omits `client_secret`.
927 // Confidential DCR clients keep the returned secret in the credential

Callers

nothing calls this directly

Calls 5

isLoopbackHttpUrlFunction · 0.90
canonicalDcrIssuerFunction · 0.85
decideDcrClientReuseFunction · 0.85
pickDcrAuthMethodFunction · 0.85
createClientFunction · 0.70

Tested by

no test coverage detected