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

Function registerDynamicClient

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

Source from the content-addressed store, hash-verified

929 });
930
931 const registerDynamicClient = (
932 input: RegisterDynamicClientInput,
933 ): Effect.Effect<OAuthClientSlug, OAuthRegisterDynamicError | StorageFailure> =>
934 Effect.gen(function* () {
935 const issuer = canonicalDcrIssuer(input.issuer, input.registrationEndpoint);
936 // Resolved before the reuse decision: a persisted client registered with
937 // a DIFFERENT callback must not be reused (strict servers 400 the
938 // authorize request), so the reuse lookup compares against this value.
939 const flowRedirectUri = input.redirectUri ?? redirectUri ?? null;
940 const reuse = yield* decideDcrClientReuse(input, issuer, flowRedirectUri);
941 if (reuse.existingSlug !== null) return reuse.existingSlug;
942
943 const slug = reuse.registrationSlug;
944 // DCR registers our callback as the client's redirect_uri — fail loudly
945 // if the executor has none rather than registering a localhost URL.
946 if (flowRedirectUri == null) {
947 return yield* new OAuthRegisterDynamicError({
948 message: REDIRECT_URI_REQUIRED_MESSAGE,
949 });
950 }
951 const authMethod = pickDcrAuthMethod(input.tokenEndpointAuthMethodsSupported);
952 const information = yield* registerDynamicClientDcr(
953 {
954 registrationEndpoint: input.registrationEndpoint,
955 metadata: {
956 client_name: input.clientName,
957 redirect_uris: [flowRedirectUri],
958 grant_types: ["authorization_code", "refresh_token"],
959 response_types: ["code"],
960 token_endpoint_auth_method: authMethod,
961 scope: input.scopes.length > 0 ? input.scopes.join(" ") : undefined,
962 },
963 },
964 { httpClientLayer, endpointUrlPolicy: deps.endpointUrlPolicy },
965 ).pipe(
966 Effect.mapError((cause) => {
967 // Some authorization servers (Vercel, and others that follow RFC 8252
968 // strictly) reject anonymous Dynamic Client Registration unless the
969 // redirect URI is loopback (http://localhost or http://127.0.0.1).
970 // Executor registers its browser origin, so any hosted, tailnet, or
971 // LAN origin trips `invalid_redirect_uri`. Turn that opaque RFC code
972 // into guidance the user can act on instead of the raw error.
973 // oxlint-disable-next-line executor/no-unknown-error-message -- boundary: OAuthDiscoveryError carries a typed `message`
974 const rawMessage = cause.message;
975 const message =
976 cause.error === "invalid_redirect_uri" && !isLoopbackHttpUrl(flowRedirectUri)
977 ? `Automatic OAuth setup failed: this server only approves loopback redirect ` +
978 `URLs (http://localhost or http://127.0.0.1) for automatic registration, but ` +
979 `Executor is using ${flowRedirectUri}. Register an OAuth app manually with that ` +
980 `redirect URL approved by the server, or run Executor on http://localhost.`
981 : `Dynamic Client Registration failed: ${rawMessage}`;
982 return new OAuthRegisterDynamicError({ message });
983 }),
984 );
985
986 // Persist the minted client. DCR-minted public clients have no secret; we
987 // store "" so the PKCE-only token exchange omits `client_secret`.
988 // 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