1

I'm attempting to use the Notion API and authorizing with their OAuth flow: https://developers.notion.com/docs/authorization

It's a standard OAuth flow. Nothing out of the ordinary.

I'm able to generate the code but I always get a invalid_client error when trying to retrieve the access_token using the following:

POST https://api.notion.com/v1/oauth/token

Content-type: application/x-www-form-urlencoded

client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET&redirect_uri=MY_REDIRECT_URL&grant_type=authorization_code&code=THE_PROVIDED_CODE

I've made sure the client id and secret are correct. I've generated new client's to test just in case something is wrong there. I have my redirect url properly registered and it's accessible.

The weird thing is, you can use the built in OAuth authorization flow in Postman or Paw and the flow works fine. I can't figure out what's different with my code vs. what they're doing.

Any ideas?

example request and response returning invalid_client

Chad Hutchins
  • 474
  • 3
  • 9
  • 1
    As far as I see in your request payload, you didn't add basic authentication header in your request. You shouldn't send your client id and secret in the request payload in this way. You have to concatenate client id and secret in the following way {client_id}:{client_secret} and encode in base64. Then you need to add this value as an authentication header in your request. – Yigit Yuksel Nov 02 '22 at 20:07

1 Answers1

0

Here is what you can do-

  1. It seems you are using application/x-www-form-urlencoded to send the body. Instead try sending the body details in JSON format only ->

     "{"grant_type":"authorization_code","code":"YOUR_CODE", "redirect_uri":"YOUR_URI"}"
    
  2. Make sure, you have followed this -> "Note that in HTTP Basic Authentication, credentials are base64 encoded before being added to the Authorization header.". I have tried this in POSTMAN and in "Basic Auth", it encodes the string automatically. (Refer below screenshot). If your API tool encodes it automatically by itself then you don't need to encode it.

Hope this helps!

POSTMAN BASIC AUTH

Sydney_dev
  • 1,448
  • 2
  • 17
  • 24