Skip to content

Commit 76b9781

Browse files
committed
Use URL.canParse instead of custom isValidUrl
1 parent f292b12 commit 76b9781

File tree

3 files changed

+2
-12
lines changed

3 files changed

+2
-12
lines changed

src/server/auth/handlers/authorize.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { RequestHandler } from "express";
22
import { z } from "zod";
3-
import { isValidUrl } from "../validation.js";
43
import { OAuthServerProvider } from "../provider.js";
54

65
export type AuthorizationHandlerOptions = {
@@ -10,7 +9,7 @@ export type AuthorizationHandlerOptions = {
109
// Parameters that must be validated in order to issue redirects.
1110
const ClientAuthorizationParamsSchema = z.object({
1211
client_id: z.string(),
13-
redirect_uri: z.string().optional().refine((value) => value === undefined || isValidUrl(value), { message: "redirect_uri must be a valid URL" }),
12+
redirect_uri: z.string().optional().refine((value) => value === undefined || URL.canParse(value), { message: "redirect_uri must be a valid URL" }),
1413
});
1514

1615
// Parameters that must be validated for a successful authorization request. Failure can be reported to the redirect URI.

src/server/auth/validation.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/shared/auth.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { z } from "zod";
2-
import { isValidUrl } from "../server/auth/validation.js";
32

43
/**
54
* RFC 8414 OAuth 2.0 Authorization Server Metadata
@@ -62,7 +61,7 @@ export const OAuthErrorSchema = z
6261
* RFC 7591 OAuth 2.0 Dynamic Client Registration metadata
6362
*/
6463
export const OAuthClientMetadataSchema = z.object({
65-
redirect_uris: z.array(z.string()).refine((uris) => uris.every(isValidUrl), { message: "redirect_uris must contain valid URLs" }),
64+
redirect_uris: z.array(z.string()).refine((uris) => uris.every((uri) => URL.canParse(uri)), { message: "redirect_uris must contain valid URLs" }),
6665
token_endpoint_auth_method: z.string().optional(),
6766
grant_types: z.array(z.string()).optional(),
6867
response_types: z.array(z.string()).optional(),

0 commit comments

Comments
 (0)