omaroughriss 030fd09460
All checks were successful
Build and Push to Registry / build-and-push (push) Successful in 27s
Update port
2025-07-03 11:02:26 +02:00

59 lines
1.6 KiB
JavaScript

const express = require('express');
const cors = require('cors');
const fetch = require('node-fetch');
// Initialisation de l'application Express
const app = express();
const PORT = process.env.PORT || 8080;
// Configuration CORS
const corsOptions = {
origin: ['http://local.lecoffreio.4nkweb:3000', 'http://localhost:3000', 'http://lecofrre-front:3000'],
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization']
};
app.use(cors(corsOptions));
app.use(express.json());
app.get('/api/v1/health', (req, res) => {
res.json({ message: 'OK' });
});
app.post('/api/v1/idnot/user/:code', async (req, res) => {
const code = req.params.code;
try {
const params = {
client_id: 'B3CE56353EDB15A9',
client_secret: '3F733549E879878344B6C949B366BB5CDBB2DB5B7F7AB7EBBEBB0F0DD0776D1C',
redirect_uri: 'http://local.lecoffreio.4nkweb:3000/authorized-client',
grant_type: 'authorization_code',
code: code
};
const response = await fetch('https://qual-connexion.idnot.fr/user/IdPOAuth2/token/idnot_idp_v1', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams(params).toString()
});
const json = await response.json();
res.json({
accessToken: json.id_token,
refreshToken: json.access_token
});
} catch (error) {
res.status(500).json({
error: 'Internal Server Error',
message: error.message
});
}
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});