Netlify API Oauth with Authorization Code

Hey all, i am attempting to set up a proper oauth flow in my web application.

The application it titled “Custom Lander Creator” under my oauth apps.

My current set up
Link that the user clicks: Netlify

This successfully takes the user to click authorize on netlify and redirects to my redirect_uri with a code.

SO I believe everything above is working properly.

However when I go to request an access token this is where the issue arises.

I’ve attempted 2 implementations of the access token call (the only different is the redirect_uri, once I tried with an encoded uri, once without to see if that would fix the issue)

code = request.GET.get(“code”)

call the netlify API to get the access token

client_id = settings.NETLIFY_CLIENT_ID
client_secret = settings.NETLIFY_SECRET

redirect_uri = “http://localhost:8000/custom_lander/options/netlify_redirect

Create the payload

payload = {
‘grant_type’: ‘authorization_code’,
‘code’: code,
‘client_id’: client_id,
‘client_secret’: client_secret,
‘redirect_uri’: redirect_uri
}

Make the POST request

response = requests.post(‘https://api.netlify.com/oauth/token’, params=payload)

The response I get is
{‘error’: ‘invalid_grant’, ‘error_description’: ‘The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.’}

I checked that the code, client_id, client_secret, redirect_uri are all correct and set, but I am still getting this error.

What do I need to change for my implementation?

We’ve responded to you in your helpdesk ticket. Kindly don’t ask the same question on multiple paltforms.