(
input: RegisterDynamicClientInput,
)
| 817 | }); |
| 818 | |
| 819 | const registerDynamicClient = ( |
| 820 | input: RegisterDynamicClientInput, |
| 821 | ): Effect.Effect<OAuthClientSlug, OAuthRegisterDynamicError | StorageFailure> => |
| 822 | Effect.gen(function* () { |
| 823 | const issuer = canonicalDcrIssuer(input.issuer, input.registrationEndpoint); |
| 824 | const reuse = yield* decideDcrClientReuse(input, issuer); |
| 825 | if (reuse.existingSlug !== null) return reuse.existingSlug; |
| 826 | |
| 827 | const slug = reuse.registrationSlug; |
| 828 | const flowRedirectUri = input.redirectUri ?? redirectUri; |
| 829 | // DCR registers our callback as the client's redirect_uri — fail loudly |
| 830 | // if the executor has none rather than registering a localhost URL. |
| 831 | if (flowRedirectUri == null) { |
| 832 | return yield* new OAuthRegisterDynamicError({ |
| 833 | message: REDIRECT_URI_REQUIRED_MESSAGE, |
| 834 | }); |
| 835 | } |
| 836 | const authMethod = pickDcrAuthMethod(input.tokenEndpointAuthMethodsSupported); |
| 837 | const information = yield* registerDynamicClientDcr( |
| 838 | { |
| 839 | registrationEndpoint: input.registrationEndpoint, |
| 840 | metadata: { |
| 841 | client_name: input.clientName, |
| 842 | redirect_uris: [flowRedirectUri], |
| 843 | grant_types: ["authorization_code", "refresh_token"], |
| 844 | response_types: ["code"], |
| 845 | token_endpoint_auth_method: authMethod, |
| 846 | scope: input.scopes.length > 0 ? input.scopes.join(" ") : undefined, |
| 847 | }, |
| 848 | }, |
| 849 | { httpClientLayer, endpointUrlPolicy: deps.endpointUrlPolicy }, |
| 850 | ).pipe( |
| 851 | Effect.mapError((cause) => { |
| 852 | // Some authorization servers (Vercel, and others that follow RFC 8252 |
| 853 | // strictly) reject anonymous Dynamic Client Registration unless the |
| 854 | // redirect URI is loopback (http://localhost or http://127.0.0.1). |
| 855 | // Executor registers its browser origin, so any hosted, tailnet, or |
| 856 | // LAN origin trips `invalid_redirect_uri`. Turn that opaque RFC code |
| 857 | // into guidance the user can act on instead of the raw error. |
| 858 | // oxlint-disable-next-line executor/no-unknown-error-message -- boundary: OAuthDiscoveryError carries a typed `message` |
| 859 | const rawMessage = cause.message; |
| 860 | const message = |
| 861 | cause.error === "invalid_redirect_uri" && !isLoopbackHttpUrl(flowRedirectUri) |
| 862 | ? `Automatic OAuth setup failed: this server only approves loopback redirect ` + |
| 863 | `URLs (http://localhost or http://127.0.0.1) for automatic registration, but ` + |
| 864 | `Executor is using ${flowRedirectUri}. Register an OAuth app manually with that ` + |
| 865 | `redirect URL approved by the server, or run Executor on http://localhost.` |
| 866 | : `Dynamic Client Registration failed: ${rawMessage}`; |
| 867 | return new OAuthRegisterDynamicError({ message }); |
| 868 | }), |
| 869 | ); |
| 870 | |
| 871 | // Persist the minted client. DCR-minted public clients have no secret; we |
| 872 | // store "" so the PKCE-only token exchange omits `client_secret`. |
| 873 | // Confidential DCR clients keep the returned secret in the credential |
| 874 | // provider. The persisted grant is interactive authorization_code. |
| 875 | // `input.scopes` was already sent to the AS at registration above; the |
| 876 | // stored client carries no scope set (the integration drives requests). |
nothing calls this directly
no test coverage detected