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

Function registerDynamicClient

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

Source from the content-addressed store, hash-verified

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