Hello,
I'm trying to create a web application using sage.
So I created a nodejs application (Oauth2 authentication server) to be able to make requests.
But I don't know why when I try to authenticate myself the server refuses me access.
I have admins rights
I don't know where this error comes from.
I have searched all afternoon in the documentation but nothing 😕
I hope someone could help me.
Here is my code of my nodejs server
const express = require('express');
const app = express();
const path = require('path');
const fs = require('fs');
const https = require('https');
const axios = require('axios');
const PORT = 3443;
const clientID ='<myclientid>';
const clientSecret ='<myclientsecret>';
app.use(express.static(__dirname + '/public'))
app.get('/callback', (req, res) => {
const requestToken = req.query.code
console.log(req.query.code);
axios({
method: 'post',
url:`https://oauth.accounting.sage.com/token&grant_type=authorization_code&code=${requestToken}client_id=${clientID}&client_secret=${clientSecret}&redirect_uri=https://localhost:3443/callback`,
headers: {
accept: 'application/json',
}
}).then((response) => {
const accessToken = response.data.access_token;
console.log(accessToken);
res.redirect(`/welcome.html?access_token=${accessToken}`)
})
})
const sslServer = https.createServer({
key:fs.readFileSync(path.join(__dirname,'cert','localhost.key')),
cert:fs.readFileSync(path.join(__dirname,'cert','localhost.crt'))
},app);
sslServer.listen(PORT,()=>console.log('Adresse : https://localhost:3443/ \nServeur SSL : port : ' + PORT));