question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PKCE Flow in web environment rejects code_verifier

See original GitHub issue

I am trying to implement the PKCE OAuth flow in a web environment. Therefore, I first call API to get a one time code:

return dropboxAuth .getAuthenticationUrl( this._redirectUrl, void 0, "code", void 0, void 0, void 0, true )

which leads to the following URL: https://www.dropbox.com/oauth2/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&code_challenge_method=S256&code_challenge=CODE_CHALLENGE

Before navigating to this link, I save the code_verifier which was generated by the Dropbox SDK. After navigating back from the URL, I get the one time code as a param: http://localhost:5000/?code=CODE

With this code, and the code_verifier I saved previously, I try to get an access token by calling (there is no method to set the code verifier, but since the app is left for navigating to the OAuth page, I somehow have to store it, therefore I set it “manually” after returning to my app, to make sure the SDK uses the same verifier as used previously to create the challenge): dropboxAuth.codeVerifier = verifier; const accessToken = await dropboxAuth.getAccessTokenFromCode(this._redirectUrl, code); which leads to the following URL:

POST | https://api.dropboxapi.com/oauth2/token?grant_type=authorization_code&code=CODE&client_id=CLIENT_ID&code_verifier=CODE_VERIFIER&redirect_uri=REDIRECT_URI

and the following result returned from Dropbox: {"error_description": "invalid code verifier", "error": "invalid_grant"}

I have checked multiple times by debugging, the code_verifier sent to the token endpoint matches the code_verifier generated by the Dropbox SDK before navigation to the OAuth page happens.

Am I missing something here? Any help is highly appreciated.

SDK-Version: 9.0.0 Browsers: Firefox 84.0.2 64bit Chrome: 87.0.4280.141 (Official Build) (64-bit)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
greg-dbcommented, Mar 25, 2021
2reactions
HerrZatackecommented, Mar 14, 2021

It’s not working for me either, I just provided a standalone example that does not require to “extract” and store and after reload “insert” the codeChallenge and codeVerifier

Read more comments on GitHub >

github_iconTop Results From Across the Web

Call Your API Using the Authorization Code Flow with PKCE
Learn how to call your API from a native, mobile, or single-page application using the Authorization Code flow using Proof Key for Code...
Read more >
RFC 7636: Proof Key for Code Exchange by OAuth Public ...
This specification describes the attack as well as a technique to mitigate against the threat through the use of Proof Key for Code...
Read more >
Securing APIs in Banking with OAuth and PKCE - F5 Networks
Exploring OAuth exchanges for financial-grade API security in banking and financial services applications and the threat of authorization ...
Read more >
Implement the OAuth 2.0 Authorization Code with PKCE Flow
OpenID Connect and OAuth 2.0 Overview. In the beginning, there were siloed web sites that didn't talk to each other, and it was...
Read more >
Support for PKCE (Proof Key for Code Exchange) in RH-SSO
Important Notes. PKCE is intended to be used in public clients in order to give an extra security. Hence, the Authorization Code Flow...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found