( input: CreateOAuthClientInput, endpointUrlPolicy: OAuthEndpointUrlPolicy | undefined, )
| 447 | }).pipe(Effect.asVoid); |
| 448 | |
| 449 | const validateClientEndpoints = ( |
| 450 | input: CreateOAuthClientInput, |
| 451 | endpointUrlPolicy: OAuthEndpointUrlPolicy | undefined, |
| 452 | ): Effect.Effect<void, StorageFailure> => |
| 453 | Effect.gen(function* () { |
| 454 | yield* validateSupportedEndpoint(input.tokenUrl, "token_url", endpointUrlPolicy); |
| 455 | if (input.resource != null && input.resource.trim().length > 0) { |
| 456 | yield* validateSupportedEndpoint(input.resource, "resource", endpointUrlPolicy); |
| 457 | } |
| 458 | if (input.grant !== "authorization_code") return; |
| 459 | yield* validateSupportedEndpoint( |
| 460 | input.authorizationUrl, |
| 461 | "authorization_url", |
| 462 | endpointUrlPolicy, |
| 463 | ); |
| 464 | if (isWellKnownOAuthMetadataUrl(input.authorizationUrl)) { |
| 465 | return yield* new StorageError({ |
| 466 | message: |
| 467 | "Invalid OAuth client endpoint configuration: authorization_url must be the OAuth authorization endpoint, not a .well-known metadata URL.", |
| 468 | cause: undefined, |
| 469 | }); |
| 470 | } |
| 471 | if (canonicalUrlString(input.authorizationUrl) === canonicalUrlString(input.tokenUrl)) { |
| 472 | return yield* new StorageError({ |
| 473 | message: |
| 474 | "Invalid OAuth client endpoint configuration: authorization_url must not equal token_url.", |
| 475 | cause: undefined, |
| 476 | }); |
| 477 | } |
| 478 | }); |
| 479 | |
| 480 | export const makeOAuthService = (deps: OAuthServiceDeps): OAuthService => { |
| 481 | const httpClientLayer = deps.httpClientLayer ?? FetchHttpClient.layer; |
no test coverage detected