OAuth2 and Twitter API

Describe the issue/error/question

Hello,
First of all, to present you the context:

  • I need to use the API v2 of twitter
  • But I need some very recent features
  • For this I need an OAuth2 authentication (so neither OAuth2 Bearer nor OAuth1)

So I can’t use the twitter node.
Therefore I tried to use the HTTP Request node with an OAuth2 credential.

I have entered my OAuth Redirect URL in my twitter App.
I have correctly entered my Access Token URL (https://api.twitter.com/2/oauth2/token), as well as my Client ID and Client Secret.

Concerning the Authorization URL, I made a URL like : https://twitter.com/i/oauth2/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https://EXEMPLE/rest/oauth2-credential/callback&scope=tweet.read%20users.read%20offline.access&state=state&code_challenge=challenge&code_challenge_method=plain

I can then connect to click on “Connect my account”, I validate the connection with my account.

What is the error message (if any)?

And then the following error appears:

{"code":0,"message":"Invalid state format returned","hint":"","stack":"ResponseError: Invalid state format returned\n    
at /usr/local/lib/node_modules/n8n/dist/src/Server.js:1065:43\n    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/layer.js:95:5)\n    at next (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/route.js:137:13)\n    at Route.dispatch (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/route.js:112:3)\n    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/layer.js:95:5)\n    at /usr/local/lib/node_modules/n8n/node_modules/express/lib/router/index.js:281:22\n    at Function.process_params (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/index.js:341:12)\n    at next (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/index.js:275:10)\n    at /usr/local/lib/node_modules/n8n/dist/src/Server.js:318:13\n    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/index.js:323:13)\n    at /usr/local/lib/node_modules/n8n/node_modules/express/lib/router/index.js:284:7\n    at Function.process_params (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/index.js:341:12)\n    at next (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/index.js:275:10)\n    at /usr/local/lib/node_modules/n8n/dist/src/Server.js:310:17\n    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/index.js:323:13)\n    at /usr/local/lib/node_modules/n8n/node_modules/express/lib/router/index.js:284:7\n    at Function.process_params (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/index.js:341:12)\n    at next (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/index.js:275:10)\n    at urlencodedParser (/usr/local/lib/node_modules/n8n/node_modules/body-parser/lib/types/urlencoded.js:91:7)\n    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/layer.js:95:5)"}

Despite the fact that I have examined the documentation (OAuth 2.0 Authorization Code Flow with PKCE | Docs | Twitter Developer Platform), I cannot understand where the error is located.

So I thank you in advance for your help

And don’t hesitate to ask me if you need more information.

Alexandre “Dadourlou” LECOEUR

Information on your n8n setup

  • n8n version: 0.162.0
  • Database you’re using (default: SQLite): Default
  • Running n8n with the execution process [own(default), main]: Default
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Hi @Dadourlou, I haven’t used Twitter’s OAuth2 yet, but could authenticate with OAuth1 without too much trouble. This allowed me to use Twitter’s API v2 as these endpoints support OAuth1 as well:

So if your goal is to simply be able to use the HTTP Request node for API v2 requests you might want to try creating “OAuth1 API” credentials in n8n with these values:

The values for Consumer Key and Consumer Secret would be provided by Twitter of course.

After connecting, v2 API requests like this one work as expected for me:

Example Workflow

As for OAuth2, this might require a closer look and will take some time unless someone else has done this already. But maybe the above already help?

1 Like

Did we manage to identify a fix for Oauth2 + Twitter yet? Few of the new V2 APIs needs Oauth2. Incidentally, I have run into the same problem. Everything looks correct from the way I have set it up, but it stills fails with an error similar to the error mentioned in the original query.

Below was the error I was presented:

ERROR RESPONSE
Error: The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.
at getAuthError (/home/roger/.nvm/versions/node/v16.0.0/lib/node_modules/n8n/node_modules/client-oauth2/src/client-oauth2.js:122:15)
at /home/roger/.nvm/versions/node/v16.0.0/lib/node_modules/n8n/node_modules/client-oauth2/src/client-oauth2.js:276:21
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /home/roger/.nvm/versions/node/v16.0.0/lib/node_modules/n8n/dist/src/Server.js:1220:36 {
body: {
error: ‘invalid_request’,
error_description: ‘Missing required parameter [code_verifier].’
},
code: ‘EAUTH’
}
Blockquote

I think I’ll wait for someone add OAuth2 as credential option into Twitter node

1 Like

Any suggestions to resolve this?

Hey all, I don’t think it’s possible right now to use OAuth 2 PKCE in the HTTP Request node as per this post: Override redirect_uri in Node OAuth2 API - #2 by RicardoE105

So you might want to consider adding a feature request for this.

As for the general Twitter node’s upgrade to v2 of the Twitter API, maybe @sirdavidoff can provide an update on the latest status?

2 Likes

Thank you for the update @MutedJam !

1 Like

No worries, I’m sorry I don’t have any better news here :frowning:

1 Like

Hey! that’s alright. Thank you again.

1 Like

So … Twitter is talk of the town these days and it does seem a little strange that we don’t have a working integration. The current node only works with OAuth v1 and this is not really publicly available (for new users) any more (unless you go through some sort of manual verification process).

Also, there are methods that are now only available with the OAuth v2.

Surprised this isn’t getting much more push, I need PKCE for Etsy integration and can’t use the current OAuth v2 Https node

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.