twitter-api-typescript-sdk: Missing required parameter [code_verifier]
await authClient.requestAccessToken(code)
crashes with
error: {
error: 'invalid_request',
error_description: 'Missing required parameter [code_verifier].'
}
I think the problem is that #codeVerifier
is undefined
here 👇
https://github.com/twitterdev/twitter-api-typescript-sdk/blob/0d4954c675dbfc566c6911adc4d4178dce926ca4/src/OAuth2User.ts#L170
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 15
@sasivarnan The solution was fairly simple. In the initial call of generateAuthURL() I use code_challenge_method: ‘plain’ and save the code_challenge that I use. Then when the user is redirected back to my platform I call the generateAuthURL() method again with the same saved code_challenge, and then the requestAccessToken() method with the code I have received.
The
1.2.0
version published 6 days ago (thanks @refarer!) allows the token to be passed on the constructor. So, now you could do something like this:state
andchallenge
and callgenerateAuthURL
; persist these values to recreate the OAuth2User later on;state
andchallenge
and callrequestAccessToken
passing thecode
received; store the token returned by that function;Using firebase functions, my simplified code is:
@jgjr I am also trying to use this SDK in a serverless environment. Could you please a minimal working code for the same?
@refarer An official example to run this SDK on serverless environment would be really appreciated.
@apecollector
I created a PR to solve this issue, I need to work with the maintainers to get a code review and eventually this feature can be merge, the PR is here if you want to take a look:
https://github.com/twitterdev/twitter-api-typescript-sdk/pull/42
Feels crazy hacky but works
@sasivarnan I was able to generate a stateless client by creating a class
That overloads the constructor and assigns the Token that I pass as a cookie from the client. You can theoretically do the same with the code_verifier property instead of doing void call to generateAuthURL to populate that property.
This is a hack and clearly this SDK isn’t designed for statelessness at this time.
Thanks @RodionChachura, you need to call
generateAuthURL
to create the code_verifier. Will add a check and throw a helpful error to improve this