Repository navigation
Conversation
…f url.parse() node-oauth#513 CodeResponseType#buildRedirectUri and AuthorizeHandler#buildErrorRedirectUri called Node's legacy url.parse(), which Node deprecates at runtime (DEP0169), so the first authorization request in every process wrote a deprecation warning to stderr. Both now use parseRedirectUri() (lib/utils/url-util.js). It parses with `new URL()` and returns the same fields url.parse() did (protocol, slashes, auth, host, port, hostname, hash, search, query, pathname, path, href), with a null-prototype `query` object when asked to parse the query. The documented return shape is unchanged and url.format() still serializes it, as option 2 in node-oauth#513 proposes, so custom response types and subclasses keep working. One difference: a redirect URI that isn't an absolute URI (RFC 6749 §3.1.2 requires one) now throws InvalidArgumentError ("Invalid parameter: `redirectUri`"), where url.parse() accepted it. Tests cover the parsed fields, url.format() output for http(s), loopback, IPv6, userinfo, percent-encoding and private-use schemes (RFC 8252), an empty query, invalid URIs, and that neither redirect path calls url.parse(). The full suite now runs without DEP0169. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017dGfgEVLYhZcaAAT8TgTZN
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes the two remaining
url.parse()calls, so the authorization endpoint no longer emits Node's runtime deprecationDEP0169. As the maintainer asked in #513, this is option 2, the non-breaking one: the redirect URI is parsed with the WHATWGURLAPI and returned in the same shapeurl.parse()gave, andurl.format()still serializes it.lib/utils/url-util.jsaddsparseRedirectUri(redirectUri, parseQueryString). It parses withnew URL()and returns the same fields asurl.parse():protocol,slashes,auth,host,port,hostname,hash,search,query,pathname,path,href. WithparseQueryStringit returns a null-prototypequeryobject, asurl.parse(value, true)does.CodeResponseType#buildRedirectUriandAuthorizeHandler#buildErrorRedirectUricall it in place ofurl.parse().updateResponse()is unchanged.Compatibility. I compared the two through the exact steps the library takes (the
query/searchchanges inbuildRedirectUri,buildErrorRedirectUriandupdateResponse, thenurl.format()). For both the success and the error redirect, the serialized redirect was identical for these URIs:[::1];…/cb?);com.example.app:/oauth2redirect,com.example.app://callback).The one behaviour change: a redirect URI that isn't an absolute URI now throws
InvalidArgumentError(Invalid parameter: \redirectUri`), whereurl.parse()` accepted it. RFC 6749 §3.1.2 requires the redirection endpoint URI to be absolute.Linked issue(s)
Closes #513. Thanks to @DmitryMarkov for the analysis there, including the two options.
Involved parts of the project
AuthorizeHandler), success and error redirects. Authorization Code Grant.CodeResponseType#buildRedirectUri.lib/utils/url-util.js, which isn't exported, soindex.d.tsis unchanged.docs/apiregenerated withnpm run docs:api: the updated@throwsline, and the new util page.Added tests?
Yes.
test/unit/utils/url-util_test.jscovers:query;url.format()output for the URIs above;url.parse()(a Sinon spy, throughhandle()for both a granted and a denied request), and thatbuildRedirectUriandbuildErrorRedirectUrithrow on a non-absolute URI.updateResponse()test now builds its input with the helper rather thanurl.parse().npm testgives 479 passing (464 before), and the whole run no longer prints DEP0169.npm run lintandnpm run formatare clean. Onnpm run test:coverage,url-util.jsis at 100% for statements, branches, functions and lines, and the suite overall is at 99.44% lines.OAuth2 standard
Reproduction
On Node 24 or later, call
OAuth2Server#authorizewith a validresponse_type=coderequest. Before this change the first call writesDEP0169to stderr; after it, nothing is written.npm testshows the same.🤖 Generated with Claude Code
https://claude.ai/code/session_017dGfgEVLYhZcaAAT8TgTZN