36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const axios = require('axios')
|
|
|
|
|
|
// TAKEN FROM OUR ALLEGRO APP CONFIGURATION --> https://apps.developer.allegro.pl/
|
|
const ALLEGRO_AUTH_TOKEN_URL = "https://allegro.pl/auth/oauth/token"
|
|
|
|
const REDIRECT_URI = "https://dropshipping.xaos.ninja"
|
|
const CLIENT_ID = "a9c8b58fa80e4daeb81ddcc342a0820d"
|
|
const CLIENT_SECRET = "7EVOUTJgNZTfh8RWTelS4oDHyML2dP5Y88qN84oCQ4SJCSt4sQcxvNrzjFp9igwC"
|
|
|
|
/* GET home page. */
|
|
router.get('/', function (req, res, next) {
|
|
const code = req?.query?.code
|
|
if (code) {
|
|
const credentials = Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString("base64")
|
|
axios.post(ALLEGRO_AUTH_TOKEN_URL, null, {
|
|
params: {
|
|
grant_type: "authorization_code",
|
|
code: code,
|
|
redirect_uri: REDIRECT_URI
|
|
},
|
|
headers: {"Authorization": `Basic ${credentials}`}
|
|
}).then(response => {
|
|
const {access_token, refresh_token} = response.data
|
|
res.render('index', {access_token: access_token, refresh_token: refresh_token});
|
|
})
|
|
} else {
|
|
res.render('index', {access_token: "", refresh_token: "", clientId: CLIENT_ID, redirectUri: REDIRECT_URI});
|
|
}
|
|
|
|
});
|
|
|
|
module.exports = router;
|