EDIT: I FOUND THE MISTAKE THAT I WAS MAKING: I WAS SENDING DATA IN JSON FORMAT AND DROPBOX DOESN'T EXPECTS DATA IN THAT FROMAT.
My question: I hope this helps others. I am trying to learn and understand the OAuth 2.0 by implementing different services such as dropbox. I am following simple 0Auth 2.0 flow, and I tested everything with postaman (client id, secret, and redirect_uri); however, when I try to access token by making a post request with url "https://api.dropboxapi.com/oauth2/token". :Here is the full error in json format (click on this link to view image)
I am successfully getting code from the first step by directing user to this url "https://www.dropbox.com/oauth2/authorize?response_type=code&state=&client_id=my_client_id&scope=files.content.read&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcallback" (the first step to verify the identity of the client or app), which is one of the parameter used in the post request for getting the token. Here is my code for making request. I have try using Axios and node-fetch (the example provided my dropbox "nodegallerytutorial" use request-promise but it's deprecated).
try {
const body = {
grant_type: "authorization_code",
code: req.query.code,
redirect_uri: "http://localhost:3000/callback",
client_id: client_id,
client_secret: client_id,
json:true
};
const response = await qaxios.post("https://api.dropboxapi.com/oauth2/token", body);
console.log({response});
res.send({response});
} catch(err)
{
res.send({error: err});
}
// below is the code for node-fetch that I used app.get("/callback", (req,res)=>{
const body = {
grant_type: "authorization_code",
code: req.query.code,
redirect_uri: "http://localhost:3000/callback",
client_id: client_id,
client_secret: client_secret
};
node_fetch("https://api.dropboxapi.com/oauth2/token", {
method:'POST',
body
}).then((response)=> response.json()).then((jsonObj)=>{
res.send({response:jsonObj});
}).catch((err)=>{
res.send({err});
});
});