Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for PKCE #245

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open

Conversation

tanettrimas
Copy link

@tanettrimas tanettrimas commented Jun 29, 2023

PR Checklist

  • I have run npm test locally and all tests are passing.
  • I have added/updated tests for any new behavior.
  • If this is a significant change, an issue has already been created where the problem / solution was discussed: [N/A, or add link to issue here]

PR Description

This PR implements #218 which adds support for PKCE, both plain and SHA256-hashed code_verifier. It is based on the RFC and should be more-or-less compliant with it.

However, it is implemented as an opt-in approach (which means that it does not support OAuth2.1 since there PKCE is always mandatory. But that was not required for the task either I assume).
This means that if the requests does not have anything related to PKCE in them, then everything works as before.

@tanettrimas
Copy link
Author

Hi @nulltoken

I have now implemented support for PKCE in this PR. Appreciate if you or somebody else of the maintainers could have a look, whenever you have the time of course 😊

@nulltoken
Copy link
Contributor

nulltoken commented Jun 29, 2023

@tanettrimas 👋 Thanks for this.

I haven't dived into it yet, however, just by skimming through it, there are two things that stand out immediately:

  • please remove the addition of the .idea folder to the source files. You can of course, optionally, add .idea/ to the .gitignore file
  • could you also revert the mass replacement of single quotes with double quotes

Those two things add a lot of noise to the diff.

@tanettrimas
Copy link
Author

Oh I did not notice that 🤦‍♂️ i’ll fix that 😄

@tanettrimas
Copy link
Author

The diff should be much more managble now 😅

@nulltoken
Copy link
Contributor

nulltoken commented Jun 29, 2023

@tanettrimas Great! It seems there still are some beautification related changes in test/helpers.test.ts and test/oauth2-service.test.ts. Could you please roll them back as well?

Note: I'm definitely not against beautification changes and code style normalization. However, I'd prefer to see them isolated in a later dedicated Pull Request.

@nulltoken nulltoken requested a review from poveden June 29, 2023 18:50
src/lib/helpers.ts Outdated Show resolved Hide resolved
src/lib/helpers.ts Outdated Show resolved Hide resolved
src/lib/types.ts Show resolved Hide resolved
@tanettrimas
Copy link
Author

Thanks for the feedback. Seems I misunderstood how the assertion functions in your codebase is supposed to be used, I will look into it and refactor it to not use them this way 😄

@nulltoken
Copy link
Contributor

@tanettrimas Looks like this going along nicely! Could you also please update the README to mention the PKCE support?

@nulltoken nulltoken requested a review from poveden July 3, 2023 19:57
) => {
let challenge: string;

switch (algorithm) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@tanettrimas How about adding a default: clause for this switch and make it throw?

Copy link
Author

Choose a reason for hiding this comment

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

Why do I need a default? it is only used with constant values

Copy link
Contributor

Choose a reason for hiding this comment

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

It's good coding practice to leave no execution branches unchecked, no matter how unlikely you think their execution might be.

Every public method (in this case, "public" means "an exported function in a module that someone else can consume") should validate its input, and throw if it receives an input it's not expected to handle.

I can see that you are already guarding against invalid values and returning an HTTP 400 error response if this happens, and today nothing in the rest of the code will pass an invalid value to this method. The thing is that tomorrow some other developer might decide to reuse this method somewhere else and not guard against invalid values, thus producing an unexpected behaviour and unintentionally introducing a bug.

test/helpers.test.ts Outdated Show resolved Hide resolved
test/helpers.test.ts Outdated Show resolved Hide resolved
const res = await request(service.requestHandler)
.get('/jwks')
.expect(200);
const res = await request(service.requestHandler).get('/jwks').expect(200);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rollback this beautification and the remaining ones below.

@nulltoken
Copy link
Contributor

@tanettrimas Hope everything's alright on your side.

Just a few minor thingies to straighten and we should be to release your feature 😉

@tanettrimas
Copy link
Author

@tanettrimas Hope everything's alright on your side.

Just a few minor thingies to straighten and we should be to release your feature 😉

Hi :) Had some things to deal with on a personal level, but I will look to finish up next week 😄

@morgan-dgk
Copy link

Just wondering if this is likely to be merged. This would be a helpful addition!

@poveden
Copy link
Contributor

poveden commented Jul 2, 2024

@tanettrimas Hi! Sorry for the LONG hiatus. Since the project has advanced a bit since this PR got started, could you please rebase it to the current HEAD so I can have a good look at it? Thanks!

@tanettrimas
Copy link
Author

Hi, will do. I must admit that I lost a bit motivation after so much nit-picking on whitespace changes. But I will rebase and then you can give another go :)

@poveden
Copy link
Contributor

poveden commented Jul 2, 2024

... I lost a bit motivation after so much nit-picking on whitespace changes. ...

I'm guessing that this is about @nulltoken's request for you to not unnecessarily beautify code in this PR. The issue is not about beautifying, but doing it so in the same PR where other things are being changed. The net effect is that there's more code for us to review, while making it hard for us to tell which changes are PR-related, and which are not.

Consider, for example, the changes you've introduced in test/oauth2-service.test.ts:

image

As far as I can tell (and I could be wrong), all of those changes are only whitespace.

The thing is: I can't easily tell if they are indeed only whitespace characters, or if you changed something relevant to the PR.

If you believe that code might be more readable than it currently is, by all means, propose a new PR with only beautification changes (alongside potential adjustments in .editorconfig/.eslintrc.json/.prettierrc.json so all future contributions stick to the proposed code style). That will allow us reviewers to focus only on style, not on the code itself.

We really appreciate the effort you're putting for the project, and we welcome more of it (if you want, of course 😛). We only ask from you to make your contributions as focused as possible. Thanks!

src/lib/oauth2-service.ts Outdated Show resolved Hide resolved
) => {
let challenge: string;

switch (algorithm) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good coding practice to leave no execution branches unchecked, no matter how unlikely you think their execution might be.

Every public method (in this case, "public" means "an exported function in a module that someone else can consume") should validate its input, and throw if it receives an input it's not expected to handle.

I can see that you are already guarding against invalid values and returning an HTTP 400 error response if this happens, and today nothing in the rest of the code will pass an invalid value to this method. The thing is that tomorrow some other developer might decide to reuse this method somewhere else and not guard against invalid values, thus producing an unexpected behaviour and unintentionally introducing a bug.

@tanettrimas
Copy link
Author

tanettrimas commented Jul 3, 2024

... I lost a bit motivation after so much nit-picking on whitespace changes. ...

I'm guessing that this is about @nulltoken's request for you to not unnecessarily beautify code in this PR. The issue is not about beautifying, but doing it so in the same PR where other things are being changed. The net effect is that there's more code for us to review, while making it hard for us to tell which changes are PR-related, and which are not.

Consider, for example, the changes you've introduced in test/oauth2-service.test.ts:

image

As far as I can tell (and I could be wrong), all of those changes are only whitespace.

The thing is: I can't easily tell if they are indeed only whitespace characters, or if you changed something relevant to the PR.

If you believe that code might be more readable than it currently is, by all means, propose a new PR with only beautification changes (alongside potential adjustments in .editorconfig/.eslintrc.json/.prettierrc.json so all future contributions stick to the proposed code style). That will allow us reviewers to focus only on style, not on the code itself.

We really appreciate the effort you're putting for the project, and we welcome more of it (if you want, of course 😛). We only ask from you to make your contributions as focused as possible. Thanks!

A fair point, but I might remind you that it is possible to filter out whitespace changes in Github just to remove the "noise". I was previously not aware that my editor added all formatting by default - some of the files were wrongly formatted in the first place. But it's fine - just very tedious.

Co-authored-by: Jordi Poveda <jorgepoveda@gmail.com>
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.

4 participants