Skip to content

Comments

feat: add proxyMode option#169

Merged
Fdawgs merged 12 commits intofastify:mainfrom
pqnet:feature/custom-error-code
Apr 24, 2025
Merged

feat: add proxyMode option#169
Fdawgs merged 12 commits intofastify:mainfrom
pqnet:feature/custom-error-code

Conversation

@pqnet
Copy link
Contributor

@pqnet pqnet commented Apr 21, 2025

Checklist

pqnet added 5 commits April 21, 2025 11:35
Signed-off-by: pqnet <119850+pqnet@users.noreply.github.com>
Signed-off-by: pqnet <119850+pqnet@users.noreply.github.com>
Signed-off-by: pqnet <119850+pqnet@users.noreply.github.com>
Signed-off-by: pqnet <119850+pqnet@users.noreply.github.com>
@pqnet
Copy link
Contributor Author

pqnet commented Apr 21, 2025

fixes #168

Copy link
Member

@Fdawgs Fdawgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this, alongside #165, should be rewritten so that there is a simple boolean proxy option that, when enabled, supports the Proxy-Authorization header and sets the correct error response code.

This way we're enforcing adherence to specifications.

@pqnet
Copy link
Contributor Author

pqnet commented Apr 22, 2025

I think this, alongside #165, should be rewritten so that there is a simple boolean proxy option that, when enabled, supports the Proxy-Authorization header and sets the correct error response code.

This way we're enforcing adherence to specifications.

I agree. Initially I thought to align with the setting for the Authorization header name, and allow customization of these other parameters as well, but then I had a change of mind, in particular since both the headers and the status code need to be changed as well. The PR was already merged and shipped though, so I continued in the same direction.

I can take care of implementing the changes + tests for this, though I'd need to clarify a couple things:

  • Support customization of authorize header #165 has already been shipped in 6.1.0, is it fine to revert the change and go in another direction although it would technically break compatibility?
  • would a proxyMode global option switching to 407/Proxy-Authenticate/Proxy-Authorization (if no header global option overrides it) be the right direction? Or we keep it an authenticate only option, requiring to manually set the header option to be compliant with the standard?

@Fdawgs
Copy link
Member

Fdawgs commented Apr 22, 2025

I think this, alongside #165, should be rewritten so that there is a simple boolean proxy option that, when enabled, supports the Proxy-Authorization header and sets the correct error response code.
This way we're enforcing adherence to specifications.

I agree. Initially I thought to align with the setting for the Authorization header name, and allow customization of these other parameters as well, but then I had a change of mind, in particular since both the headers and the status code need to be changed as well. The PR was already merged and shipped though, so I continued in the same direction.

I can take care of implementing the changes + tests for this, though I'd need to clarify a couple things:

* [Support customization of authorize header #165](https://github.com/fastify/fastify-basic-auth/pull/165) has already been shipped in 6.1.0, is it fine to revert the change and go in another direction although it would technically break compatibility?

* would a `proxyMode` global option switching to `407`/`Proxy-Authenticate`/`Proxy-Authorization` (if no `header` global option overrides it) be the right direction? Or we keep it an `authenticate` only option, requiring to manually set the `header` option to be compliant with the standard?

Thanks @pqnet, we'd just need to do a major release to switch to this proxyMode direction, no biggy. :)

@fastify/plugins wdyt?

@pqnet
Copy link
Contributor Author

pqnet commented Apr 23, 2025

@Fdawgs I have updated this PR to implement the proxyMode option rather than allowing any custom http code, for now without stripping the authenticate.header option support to maintain backward compatibility. Once you discuss between maintainers and decide that removing it is the best option it is as simple as changing one line of code, one of typings, and remove the two failing test cases and one paragraph in the docs referring to that. Most of the existing code for the custom authorization header is still required to support proxyMode

Signed-off-by: pqnet <119850+pqnet@users.noreply.github.com>
@Fdawgs
Copy link
Member

Fdawgs commented Apr 23, 2025

This is perfect, thanks @pqnet. Will take a proper look this evening.

Signed-off-by: Frazer Smith <frazer.dev@icloud.com>
Signed-off-by: Frazer Smith <frazer.dev@icloud.com>
@Fdawgs Fdawgs changed the title Feature/custom error code feat: add proxyMode option Apr 23, 2025
@Fdawgs Fdawgs linked an issue Apr 23, 2025 that may be closed by this pull request
2 tasks
@Fdawgs Fdawgs requested a review from a team April 23, 2025 15:43
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Fdawgs Fdawgs requested a review from Copilot April 24, 2025 13:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new option, proxyMode, to enable HTTP proxy authentication instead of resource authentication. Key changes include:

  • Adding proxyMode support in type definitions and tests.
  • Updating the main plugin logic in index.js to adjust header names, status codes, and error handling when proxyMode is enabled.
  • Enhancing the documentation in README.md to reflect the new proxyMode functionality.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

File Description
types/index.test-d.ts Adds tests for the new proxyMode option
test/index.test.js Implements tests validating proxy authentication logic
index.js Updates authentication logic to support proxyMode
README.md Updates documentation for proxyMode option

Co-authored-by: KaKa <23028015+climba03003@users.noreply.github.com>
Signed-off-by: Frazer Smith <frazer.dev@icloud.com>
@Fdawgs Fdawgs requested a review from climba03003 April 24, 2025 13:47
@Fdawgs Fdawgs merged commit 05bc284 into fastify:main Apr 24, 2025
11 checks passed
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.

Support customization of the authentication failed status code

4 participants