Skip to content

feat: add followRedirects option to follow 30x responses - #506

Open
ChrisZieba wants to merge 1 commit into
auth0:masterfrom
ChrisZieba:follow-redirects
Open

feat: add followRedirects option to follow 30x responses#506
ChrisZieba wants to merge 1 commit into
auth0:masterfrom
ChrisZieba:follow-redirects

Conversation

@ChrisZieba

Copy link
Copy Markdown

Description

Adds a followRedirects client option (default false) that, when enabled, follows 3xx redirect responses from the JWKS endpoint instead of treating them as errors.

Previously any 3xx status fell through the statusCode < 200 || statusCode >= 300 check in the request wrapper and was rejected as an HTTP error. With followRedirects: true, the wrapper now follows the Location header to the final response.

Changes

  • src/wrappers/request.js — refactored the request into a recursive makeRequest(uri, redirectCount) helper. On a 3xx response with a Location header (and followRedirects enabled) it drains the redirect body, resolves the location against the current URL (so both absolute and relative redirects work), and re-issues the request reusing the same headers / timeout / agent. The chain is capped at 10 hops to guard against redirect loops.
  • src/JwksClient.js — added followRedirects: false to the default options and threaded it through to the request() call in getKeys().
  • index.d.ts — added followRedirects?: boolean to OptionsBase.
  • README.md — documented the new option.
  • tests/request.tests.js — added coverage for: following an absolute 30x redirect, following a relative redirect, not following when disabled, and the max-redirects guard.

Behavior / compatibility

Default is false, so existing behavior is unchanged — a 3xx still surfaces as an error unless the option is opted into.

Testing

  • npm run lint — clean
  • npm test — 94 JS tests passing (incl. 4 new redirect tests) + 3 TS tests passing

Add a `followRedirects` client option (default `false`) that, when
enabled, follows 3xx redirect responses from the JWKS endpoint instead
of treating them as errors.

The request wrapper now resolves the `Location` header against the
current URL so both absolute and relative redirects are supported, and
caps the redirect chain at 10 hops to guard against loops.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ChrisZieba
ChrisZieba requested a review from a team as a code owner June 9, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant