Skip to content

Conversation

martinssonj
Copy link
Contributor

Summary

For getAuthorizationCode it is expected that the code contains a codeChallenge and a codeChallengeMethod but in saveAuthorizationCode it is not saved.

By adding the possibility to save codeChallenge and codeChallengeMethod the PKCE flow now works without any other changes.

Linked issue(s)

#76

Involved parts of the project

Authorization Code Flow with PKCE

Added tests?

Yes

OAuth2 standard

OAuth 2.0 RFC 7636

Reproduction

First authorize

curl --location --request POST 'http://localhost:8081/oauth2/authorize' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=test' \
--data-urlencode 'scope=openid' \
--data-urlencode 'redirect_uri=http://localhost:5000/callback' \
--data-urlencode 'state=e3e96ed8-889d-4dac-a680-6a47f5efbb14' \
--data-urlencode 'response_type=code' \
--data-urlencode 'username=user@user.com' \
--data-urlencode 'password=password' \
--data-urlencode 'code_challenge=challenge' \
--data-urlencode 'code_challenge_method=plain'

Use code from redirect and create token by:

curl --location --request POST 'http://localhost:8081/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=test' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'state=e3e96ed8-889d-4dac-a680-6a47f5efbb14' \
--data-urlencode 'response_type=code' \
--data-urlencode 'code_verifier=challenge' \
--data-urlencode 'code_challenge_method=plain' \
--data-urlencode 'code=7590791f34ddd18b7cdc398eee673051397bde3230533cdc24bd472ee472be02' \
--data-urlencode 'redirect_uri=http://localhost:5000/callback'

@jankapunkt
Copy link
Member

Thank you so much @martinssonj I will take a look at this 👍

@jankapunkt jankapunkt added this to the v4.3 milestone Oct 31, 2022
@jankapunkt jankapunkt added the compliance 📜 OAuth 2.0 standard compliance label Oct 31, 2022
@jankapunkt jankapunkt merged commit 19f7dc4 into node-oauth:feature-pkce Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compliance 📜 OAuth 2.0 standard compliance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants