I am trying to use OAuth2 for a Notion integration, but keep getting the error “invalid_grant”. I can not seem to figure out what I am doing wrong, any help would be appreciated.
app.get('/auth', (req, res) => {
let query = req.query;
console.log(query);
if ('code' in query) {
res.sendFile(`${__dirname}/pages/auth.html`);
let auth = Buffer.from(`${process.env.CLIENT_ID}:${process.env.CLIENT_SECRET}`)
.toString('base64');
let options = {
method: 'post',
url: 'https://api.notion.com/v1/oauth/token',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Basic ${auth}`
},
data: {
grant_type: 'authorization_code',
code: query.code,
redirect_uri: 'https://nodeserver.micahrao.repl.co'
}
};
axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.log(err));
} else res.redirect('/');
});