(
input: RegisterDynamicClientInput,
)
| 760 | }); |
| 761 | |
| 762 | const registerDynamicClient = ( |
| 763 | input: RegisterDynamicClientInput, |
| 764 | ): Effect.Effect<OAuthClientSlug, OAuthRegisterDynamicError | StorageFailure> => |
| 765 | Effect.gen(function* () { |
| 766 | const issuer = canonicalDcrIssuer(input.issuer, input.registrationEndpoint); |
| 767 | const reuse = yield* decideDcrClientReuse(input, issuer); |
| 768 | if (reuse.existingSlug !== null) return reuse.existingSlug; |
| 769 | |
| 770 | const slug = reuse.registrationSlug; |
| 771 | const flowRedirectUri = input.redirectUri ?? redirectUri; |
| 772 | // DCR registers our callback as the client's redirect_uri — fail loudly |
| 773 | // if the executor has none rather than registering a localhost URL. |
| 774 | if (flowRedirectUri == null) { |
| 775 | return yield* new OAuthRegisterDynamicError({ |
| 776 | message: REDIRECT_URI_REQUIRED_MESSAGE, |
| 777 | }); |
| 778 | } |
| 779 | const authMethod = pickDcrAuthMethod(input.tokenEndpointAuthMethodsSupported); |
| 780 | const information = yield* registerDynamicClientDcr( |
| 781 | { |
| 782 | registrationEndpoint: input.registrationEndpoint, |
| 783 | metadata: { |
| 784 | client_name: input.clientName, |
| 785 | redirect_uris: [flowRedirectUri], |
| 786 | grant_types: ["authorization_code", "refresh_token"], |
| 787 | response_types: ["code"], |
| 788 | token_endpoint_auth_method: authMethod, |
| 789 | scope: input.scopes.length > 0 ? input.scopes.join(" ") : undefined, |
| 790 | }, |
| 791 | }, |
| 792 | { httpClientLayer, endpointUrlPolicy: deps.endpointUrlPolicy }, |
| 793 | ).pipe( |
| 794 | Effect.mapError((cause) => { |
| 795 | // Some authorization servers (Vercel, and others that follow RFC 8252 |
| 796 | // strictly) reject anonymous Dynamic Client Registration unless the |
| 797 | // redirect URI is loopback (http://localhost or http://127.0.0.1). |
| 798 | // Executor registers its browser origin, so any hosted, tailnet, or |
| 799 | // LAN origin trips `invalid_redirect_uri`. Turn that opaque RFC code |
| 800 | // into guidance the user can act on instead of the raw error. |
| 801 | // oxlint-disable-next-line executor/no-unknown-error-message -- boundary: OAuthDiscoveryError carries a typed `message` |
| 802 | const rawMessage = cause.message; |
| 803 | const message = |
| 804 | cause.error === "invalid_redirect_uri" && !isLoopbackHttpUrl(flowRedirectUri) |
| 805 | ? `Automatic OAuth setup failed: this server only approves loopback redirect ` + |
| 806 | `URLs (http://localhost or http://127.0.0.1) for automatic registration, but ` + |
| 807 | `Executor is using ${flowRedirectUri}. Register an OAuth app manually with that ` + |
| 808 | `redirect URL approved by the server, or run Executor on http://localhost.` |
| 809 | : `Dynamic Client Registration failed: ${rawMessage}`; |
| 810 | return new OAuthRegisterDynamicError({ message }); |
| 811 | }), |
| 812 | ); |
| 813 | |
| 814 | // Persist the minted client. DCR-minted public clients have no secret; we |
| 815 | // store "" so the PKCE-only token exchange omits `client_secret`. |
| 816 | // Confidential DCR clients keep the returned secret in the credential |
| 817 | // provider. The persisted grant is interactive authorization_code. |
| 818 | // `input.scopes` was already sent to the AS at registration above; the |
| 819 | // stored client carries no scope set (the integration drives requests). |
nothing calls this directly
no test coverage detected