I want to integrate the login with twitter in our Odoo ERP system.

So for that, I’m using OAuth 2.0 Authorization Code Flow with PKCE.

I’m getting error when try to get access token.

Would you please check following steps which I have done?
If anything wrong, please let me know.

Steps:

  1. I have construct an authorize URL.
  2. I have got code from oauth2/authorize.
  3. I try to get an access token through a POST request using following URL ‘oauth2/token’.
  4. I got this in response {“error”:“unauthorized_client”,“error_description”:“Missing valid authorization header”}

Note :- I refer this document for get token [OAuth 2.0 Making requests on behalf of users | Docs | Twitter Developer Platform]

Please check and revert.

It is impossible to know what the source of the error is without knowing anything about this system, so maybe developers / support for Odoo are a better place to ask. If not, what language is this coded in? Is this using some existing library or coded from scratch?

Missing authorization header means that something was not done correctly to construct the http request - the header is not there.

We have used python language for integration, and we used Rest API for sending a request for authentication.

For that we have used the python packages requests to send a POST, GET request.

Please check the following operation I did for authentication using OAuth2.

Step 1: Authorize

We refer to Authorization Code Flow with PKCE.

First, we redirect to this URL = “/i/oauth2/authorize?response_type=code&client_id=UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ&redirect_uri=/twitter_oauth/authorize&scope=users.read&state=sXPDZqSiOnTFB1kwmcwNdRwPoSLRth&code_challenge=challenge&code_challenge_method=plain)”

Then open one login page of twitter.
After add credentials of user, they redirect to authorize user page. (Please see attached image.)

Then hit on Authorize App Button we got response from Twitter API as below.

{‘state’: ‘sXPDZqSiOnTFB1kwmcwNdRwPoSLRth’, ‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’}

Step 2: Get Access Token
We have sent request to (/2/oauth2/token) for get access token using code which I got in step1 response.

Please check below request and response code.

import requests
import json

headers = {‘Content-Type’: ‘application/x-www-form-urlencoded’}

params = {
‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’,
‘grant_type’: ‘authorization_code’,
‘client_id’: ‘UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ’,
‘client_secret’: ‘ns_dz4hOw6DLLXkYc7CcpbRxwDERHaX6DgNCicfqkAu9pws7Dx’,
‘redirect_uri’: ‘redirect_uri’, ‘code_verifier’: ‘challenge’}

url = ''token_url"

token_request = requests.post(url=url, params=params, headers=headers)

Or
I have also set params in body instead of params parameter but also getting same issue.
token_request = requests.post(url=url, body=jsPreformatted texton.dumps(params), headers=headers)

response = token_request.json()

We’re getting responses below:
response = {“error”:“unauthorized_client”,“error_description”:“Missing valid authorization header”}

Please check the above steps and let me know.

Thanks,
Smith

We have used python language for integration, and we used Rest API for sending a request for authentication.

For that we have used the python packages requests to send a POST, GET request.

Please check the following operation I did for authentication using OAuth2.

Step 1: Authorize

We refer to Authorization Code Flow with PKCE.

First, we redirect to this URL = “/i/oauth2/authorize?response_type=code&client_id=UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ&redirect_uri=/twitter_oauth/authorize&scope=users.read&state=sXPDZqSiOnTFB1kwmcwNdRwPoSLRth&code_challenge=challenge&code_challenge_method=plain”

Then open one login page of twitter.
After add credentials of user, they redirect to authorize user page. (Please see attached image.)

Then hit on Authorize App Button we got response from Twitter API as below.

{‘state’: ‘sXPDZqSiOnTFB1kwmcwNdRwPoSLRth’, ‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’}

Step 2: Get Access Token
We have sent request to this URL “/2/oauth2/token” for get access token using code which I got in step1 response.

Please check below request and response code.

import requests
import json

headers = {‘Content-Type’: ‘application/x-www-form-urlencoded’}

params = {
‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’,
‘grant_type’: ‘authorization_code’,
‘client_id’: ‘UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ’,
‘client_secret’: ‘ns_dz4hOw6DLLXkYc7CcpbRxwDERHaX6DgNCicfqkAu9pws7Dx’,
‘redirect_uri’: ‘/twitter_oauth/authorize’, ‘code_verifier’: ‘challenge’}

url = ‘’/2/oauth2/token"

token_request = requests.post(url=url, params=params, headers=headers)

Or
I have also set params in body instead of params parameter but also getting same issue.
token_request = requests.post(url=url, body=json.dumps(params), headers=headers)

response = token_request.json()

We’re getting response as below:
response = {“error”:“unauthorized_client”,“error_description”:“Missing valid authorization header”}

Note - We removed domain from all link due to constrains.

Please check above steps and let me know.

Thanks,
Smith

We have used python language for integration, and we used Rest API for sending a request for authentication.

For that we have used the python packages requests to send a POST, GET request.

Please check the following operation I did for authentication using OAuth2.

Step 1: Authorize

We refer to Authorization Code Flow with PKCE.

First, we redirect to this URL = “i/oauth2/authorize?response_type=code&client_id=UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ&redirect_uri=/twitter_oauth%2Fauthorize&scope=users.read&state=sXPDZqSiOnTFB1kwmcwNdRwPoSLRth&code_challenge=challenge&code_challenge_method=plain”

Then open one login page of twitter.
After add credentials of user, they redirect to authorize user page. (Please see attached image.)

Then hit on Authorize App Button we got response from Twitter API as below.

{‘state’: ‘sXPDZqSiOnTFB1kwmcwNdRwPoSLRth’, ‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’}

Step 2: Get Access Token
We have sent request to this URL “/2/oauth2/token” for get access token using code which I got in step1 response.

Please check below request and response code.

import requests
import json

headers = {‘Content-Type’: ‘application/x-www-form-urlencoded’}

params = {
‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’,
‘grant_type’: ‘authorization_code’,
‘client_id’: ‘UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ’,
‘client_secret’: ‘ns_dz4hOw6DLLXkYc7CcpbRxwDERHaX6DgNCicfqkAu9pws7Dx’,
‘redirect_uri’: ‘/twitter_oauth/authorize’, ‘code_verifier’: ‘challenge’}

url = ‘’/2/oauth2/token"

token_request = requests.post(url=url, params=params, headers=headers)

Or
I have also set params in body instead of params parameter but also getting same issue.
token_request = requests.post(url=url, body=json.dumps(params), headers=headers)

response = token_request.json()

We’re getting response as below:
response = {“error”:“unauthorized_client”,“error_description”:“Missing valid authorization header”}

Please Note- We removed domain from all link due to constrains.

Please check above steps and let me know.

Thanks,
Smith

We have used python language for integration, and we used Rest API for sending a request for authentication.

For that we have used the python packages requests to send a POST, GET request.

Please check the following operation I did for authentication using OAuth2.

Step 1: Authorize

We refer to Authorization Code Flow with PKCE.

First, we redirect to this URL = “i/oauth2/authorize?response_type=code&client_id=UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ&redirect_uri=/twitter_oauth/authorize&scope=users.read&state=sXPDZqSiOnTFB1kwmcwNdRwPoSLRth&code_challenge=challenge&code_challenge_method=plain”

Then open one login page of twitter.
After add credentials of user, they redirect to authorize user page. (Please see attached image.)

Then hit on Authorize App Button we got response from Twitter API as below.

{‘state’: ‘sXPDZqSiOnTFB1kwmcwNdRwPoSLRth’, ‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’}

Step 2: Get Access Token
We have sent request to this URL “/2/oauth2/token” for get access token using code which I got in step1 response.

Please check below request and response code.

import requests
import json

headers = {‘Content-Type’: ‘application/x-www-form-urlencoded’}

params = {
‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’,
‘grant_type’: ‘authorization_code’,
‘client_id’: ‘UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ’,
‘client_secret’: ‘ns_dz4hOw6DLLXkYc7CcpbRxwDERHaX6DgNCicfqkAu9pws7Dx’,
‘redirect_uri’: ‘/twitter_oauth/authorize’, ‘code_verifier’: ‘challenge’}

url = “/2/oauth2/token”

token_request = requests.post(url=url, params=params, headers=headers)

Or
I have also set params in body instead of params parameter but also getting same issue.
token_request = requests.post(url=url, body=json.dumps(params), headers=headers)

response = token_request.json()

We’re getting response as below:
response = {“error”:“unauthorized_client”,“error_description”:“Missing valid authorization header”}

Please Note- We remove domain from all link.

Please check above steps and let me know.

Thanks,
Smith

We have used python language for integration, and we used Rest API for sending a request for authentication.

For that we have used the python packages requests to send a POST, GET request.

Please check the following operation I did for authentication using OAuth2.

Step 1: Authorize

We refer to Authorization Code Flow with PKCE.

First, we redirect to this URL = “i/oauth2/authorize?response_type=code&client_id=UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ&redirect_uri=/twitter_oauth/authorize&scope=users.read&state=sXPDZqSiOnTFB1kwmcwNdRwPoSLRth&code_challenge=challenge&code_challenge_method=plain”

Then open one login page of twitter.
After add credentials of user, they redirect to authorize user page. (Please see attached image.)

Then hit on Authorize App Button we got response from Twitter API as below.

{‘state’: ‘sXPDZqSiOnTFB1kwmcwNdRwPoSLRth’, ‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’}

Step 2: Get Access Token
We have sent request to this URL “/2/oauth2/token” for get access token using code which I got in step1 response.

Please check below request and response code.

import requests
import json

headers = {‘Content-Type’: ‘application/x-www-form-urlencoded’}

params = {
‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’,
‘grant_type’: ‘authorization_code’,
‘client_id’: ‘UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ’,
‘client_secret’: ‘ns_dz4hOw6DLLXkYc7CcpbRxwDERHaX6DgNCicfqkAu9pws7Dx’,
‘redirect_uri’: ‘/twitter_oauth/authorize’, ‘code_verifier’: ‘challenge’}

url = “/2/oauth2/token”

token_request = requests.post(url=url, params=params, headers=headers)

Or
I have also set params in body instead of params parameter but also getting same issue.
token_request = requests.post(url=url, body=json.dumps(params), headers=headers)

response = token_request.json()

We’re getting response as below:
response = {“error”:“unauthorized_client”,“error_description”:“Missing valid authorization header”}

Please Note- We remove domain from all link.

Please check above steps and let me know.

Thanks,
Smith

We have used python language for integration, and we used Rest API for sending a request for authentication.

For that we have used the python packages requests to send a POST, GET request.

Please check the following operation I did for authentication using OAuth2.

Step 1: Authorize

We refer to Authorization Code Flow with PKCE.

First, we redirect to this URL = “i/oauth2/authorize?response_type=code&client_id=UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ&redirect_uri=/twitter_oauth/authorize&scope=users.read&state=sXPDZqSiOnTFB1kwmcwNdRwPoSLRth&code_challenge=challenge&code_challenge_method=plain”

Then open one login page of twitter.
After add credentials of user, they redirect to authorize user page. (Please see attached image.)

Then hit on Authorize App Button we got response from Twitter API as below.

{‘state’: ‘sXPDZqSiOnTFB1kwmcwNdRwPoSLRth’, ‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’}

Step 2: Get Access Token
We have sent request to this URL “/2/oauth2/token” for get access token using code which I got in step1 response.

Please check below request and response code.

import requests
import json

headers = {‘Content-Type’: ‘application/x-www-form-urlencoded’}

params = {
‘code’: ‘Sk5odzUzN0xZZXM3YTA1NnpxbWo4S2h0N2hZVmJtQzQ0LXdWUW1GVlhxbHo1OjE2NzQ3OTY2NjQxODQ6MToxOmFjOjE’,
‘grant_type’: ‘authorization_code’,
‘client_id’: ‘UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ’,
‘client_secret’: ‘ns_dz4hOw6DLLXkYc7CcpbRxwDERHaX6DgNCicfqkAu9pws7Dx’,
‘redirect_uri’: ‘/twitter_oauth/authorize’, ‘code_verifier’: ‘challenge’}

url = “/2/oauth2/token”

token_request = requests.post(url=url, params=params, headers=headers)

Or
I have also set params in body instead of params parameter but also getting same issue.
token_request = requests.post(url=url, body=json.dumps(params), headers=headers)

response = token_request.json()

We’re getting response as below:
response = {“error”:“unauthorized_client”,“error_description”:“Missing valid authorization header”}

Please Note- We remove domain from all link.

Please check above steps and let me know.

Thanks,
Smith

Hello Team,

I have also try with different way to get access token but I’m getting same response with error “unauthorized client”.

Please check below request and response using python.

Blockquote
import base64
import hashlib
import os
import re
import json
import requests
from requests.auth import AuthBase, HTTPBasicAuth
from requests_oauthlib import OAuth2Session
os.environ[‘OAUTHLIB_INSECURE_TRANSPORT’] = ‘1’
redirect_uri = “https://synconics-16-0-apps-test-7074059.dev.odoo.com/twitter_oauth/authorize
scopes = [“users.read”]
client_id = “UXo4RFF1ZzNtYUJqaWdjREtRTjQ6MTpjaQ”
code_verifier = base64.urlsafe_b64encode(os.urandom(30)).decode(“utf-8”)
code_verifier = re.sub(“[^a-zA-Z0-9]+”, “”, code_verifier)
code_challenge = hashlib.sha256(code_verifier.encode(“utf-8”)).digest()
code_challenge = base64.urlsafe_b64encode(code_challenge).decode(“utf-8”)
code_challenge = code_challenge.replace(“=”, “”)
oauth = OAuth2Session(client_id, redirect_uri=redirect_uri, scope=scopes)
auth_url = “https://twitter.com/i/oauth2/authorize
authorization_url, state = oauth.authorization_url(
auth_url, code_challenge=code_challenge, code_challenge_method=“S256”
)
print(
“Visit the following URL to authorize your App on behalf of your Twitter handle in a browser:”
)
print(authorization_url)
authorization_response = input(
“Paste in the full URL after you’ve authorized your App:\n”
)
token_url = “https://api.twitter.com/2/oauth2/token
token = oauth.fetch_token(
token_url=token_url,
authorization_response=authorization_response,
auth=auth,
client_id=client_id,
include_client_id=True,
code_verifier=code_verifier,
)
access = token[“access_token”]

Error Response: oauthlib.oauth2.rfc6749.errors.UnauthorizedClientError: (unauthorized_client) Missing valid authorization header

Please give me solution to get access token using oauth2 for login with twitter in behalf of user.

Does this example work for you? It implements oAuth2.0 PKCE flow: Twitter-API-v2-sample-code/create_bookmark.py at main · twitterdev/Twitter-API-v2-sample-code · GitHub

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