( input: CreateOAuthClientInput, endpointUrlPolicy: OAuthEndpointUrlPolicy | undefined, )
| 391 | }).pipe(Effect.asVoid); |
| 392 | |
| 393 | const validateClientEndpoints = ( |
| 394 | input: CreateOAuthClientInput, |
| 395 | endpointUrlPolicy: OAuthEndpointUrlPolicy | undefined, |
| 396 | ): Effect.Effect<void, StorageFailure> => |
| 397 | Effect.gen(function* () { |
| 398 | yield* validateSupportedEndpoint(input.tokenUrl, "token_url", endpointUrlPolicy); |
| 399 | if (input.resource != null && input.resource.trim().length > 0) { |
| 400 | yield* validateSupportedEndpoint(input.resource, "resource", endpointUrlPolicy); |
| 401 | } |
| 402 | if (input.grant !== "authorization_code") return; |
| 403 | yield* validateSupportedEndpoint( |
| 404 | input.authorizationUrl, |
| 405 | "authorization_url", |
| 406 | endpointUrlPolicy, |
| 407 | ); |
| 408 | if (isWellKnownOAuthMetadataUrl(input.authorizationUrl)) { |
| 409 | return yield* new StorageError({ |
| 410 | message: |
| 411 | "Invalid OAuth client endpoint configuration: authorization_url must be the OAuth authorization endpoint, not a .well-known metadata URL.", |
| 412 | cause: undefined, |
| 413 | }); |
| 414 | } |
| 415 | if (canonicalUrlString(input.authorizationUrl) === canonicalUrlString(input.tokenUrl)) { |
| 416 | return yield* new StorageError({ |
| 417 | message: |
| 418 | "Invalid OAuth client endpoint configuration: authorization_url must not equal token_url.", |
| 419 | cause: undefined, |
| 420 | }); |
| 421 | } |
| 422 | }); |
| 423 | |
| 424 | export const makeOAuthService = (deps: OAuthServiceDeps): OAuthService => { |
| 425 | const httpClientLayer = deps.httpClientLayer ?? FetchHttpClient.layer; |
no test coverage detected