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

Function registerDynamicClient

packages/core/sdk/src/oauth-discovery.ts:493–579  ·  view source on GitHub ↗
(
  input: RegisterDynamicClientInput,
  options: DiscoveryRequestOptions = {},
)

Source from the content-addressed store, hash-verified

491};
492
493export const registerDynamicClient = (
494 input: RegisterDynamicClientInput,
495 options: DiscoveryRequestOptions = {},
496): Effect.Effect<OAuthClientInformation, OAuthDiscoveryError> =>
497 Effect.gen(function* () {
498 yield* validateEndpointUrl(
499 input.registrationEndpoint,
500 "registration_endpoint",
501 options.endpointUrlPolicy,
502 ).pipe(
503 Effect.mapError(
504 (cause) =>
505 new DcrTransport({
506 detail: "registration_endpoint must use https: or loopback http:",
507 cause,
508 }),
509 ),
510 );
511
512 const headers: Record<string, string> = {
513 "content-type": "application/json",
514 accept: "application/json",
515 };
516 if (input.initialAccessToken) {
517 headers.authorization = `Bearer ${input.initialAccessToken}`;
518 }
519
520 let request = HttpClientRequest.post(input.registrationEndpoint).pipe(
521 HttpClientRequest.bodyJsonUnsafe(buildDcrBody(input.metadata)),
522 );
523 for (const [name, value] of Object.entries(headers)) {
524 request = HttpClientRequest.setHeader(request, name, value);
525 }
526
527 const response = yield* executeText(
528 request,
529 options,
530 "Dynamic Client Registration request failed",
531 ).pipe(
532 Effect.mapError(
533 (cause) =>
534 new DcrTransport({
535 detail: "Dynamic Client Registration request failed",
536 cause,
537 }),
538 ),
539 );
540
541 // Accept both 200 and 201 as success — RFC 7591 mandates 201, but
542 // Todoist (and others) return 200 OK with the client information body.
543 if (response.status !== 200 && response.status !== 201) {
544 return yield* interpretDcrFailure(response.status, response.body);
545 }
546
547 return yield* decodeClientInformationJson(response.body).pipe(
548 Effect.mapError(
549 (err) =>
550 new OAuthDiscoveryError({

Callers 2

Calls 4

validateEndpointUrlFunction · 0.85
buildDcrBodyFunction · 0.85
executeTextFunction · 0.85
interpretDcrFailureFunction · 0.85

Tested by

no test coverage detected