I am building an application using expo/react-native that has an authentication component to it using the authorization flow. Basically, so far I have successfully obtained an authorization code via the ‘authorize’ endpoint but I am having trouble retrieving an access token with said code. Let me show you my POST request:
try { const settings = { method: 'POST', headers: {'content-type': 'application/x-www-form-urlencoded'}, form: { grant_type: 'authorization_code', client_id: CLIENT_ID, client_secret: CLIENT_SECRET, code: code, redirect_uri: url } } let response = await fetch('https://spikeedev.auth0.com/oauth/token', settings); let responseJson = await response.json(); return responseJson; } catch (error) { console.error(error); }
Response:
{
“error”: “access_denied”,
“error_description”: “Unauthorized”
}
Here are a few notes:
- Yes, CLIENT_ID and CLIENT_SECRET are just placeholders here (that isn’t the issue)
- ‘url’ is a variable holding the same callback url I used when I got the code. It is the custom callback url that expo generates for my application using ‘AuthSession’
- I have also tried making this request using the ‘Postman’ application to see if there was any difference…but I got the same response.
I have checked…double checked…triple checked… HELP!