// Import the express lirbary const express = require('express') // Import the axios library, to make HTTP requests const axios = require('axios') // This is the client ID and client secret that you obtained // while registering the application const clientID = 'karkarcar' const clientSecret = 'Isr3hCHbPSadkF0V44AnIubhJO3XeYzZ' // Create a new express application and use // the express static middleware, to serve all files // inside the public directory const app = express() app.use(express.static(__dirname + '/public')) app.get('/oauth/redirect', (req, res) => { // The req.query object has the query params that // were sent to this route. We want the `code` param const requestToken = req.query.code console.log(requestToken, requestToken) axios({ // make a POST request method: 'post', // to the Github authentication API, with the client ID, client secret // and request token url: `http://localhost:8180/realms/master/protocol/openid-connect?client_id=${clientID}&client_secret=${clientSecret}&code=${requestToken}&scope=openid`, //url: `https://github.com/login/oauth/access_token?client_id=${clientID}&client_secret=${clientSecret}&code=${requestToken}`, // Set the content type header, so that we get the response in JSOn headers: { accept: 'application/json' } }).then((response) => { // Once we get the response, extract the access token from // the response body const accessToken = response.data.access_token // redirect the user to the welcome page, along with the access token res.redirect(`/welcome.html?access_token=${accessToken}`) }) }) // Start the server on port 8080 app.listen(8080)