From 2873f65d2a46fa13c15cd74667a63f7e3a3ae585 Mon Sep 17 00:00:00 2001 From: lucabertelli Date: Tue, 24 Oct 2023 17:53:25 +0200 Subject: [PATCH] fix(github): fix github enterprise authentication --- .gitignore | 3 ++- controllers/auth/read.auth.controller.js | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 90ca8d7..8ff358b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ assets/* *.txt sample.json .env -.test/ \ No newline at end of file +.test/ +.vscode/launch.json diff --git a/controllers/auth/read.auth.controller.js b/controllers/auth/read.auth.controller.js index 38fce51..3930641 100644 --- a/controllers/auth/read.auth.controller.js +++ b/controllers/auth/read.auth.controller.js @@ -10,6 +10,7 @@ const logger = require('../../service-library/helpers/logger.helpers') const jwtHelpers = require('../../service-library/helpers/jwt.helpers') const authHelpers = require('../../helpers/auth.helpers') const k8sHelpers = require('../../service-library/helpers/k8s.helpers') +const stringHelpers = require('../../service-library/helpers/string.helpers') const responseHelpers = require('../../helpers/response.helpers') const { k8sConstants } = require('../../service-library/constants') @@ -42,11 +43,16 @@ router.get( passport.authenticate('github', { scope: ['user:email'] }) ) -router.get('/github/callback', (req, res, next) => { +router.get('/github/callback', async (req, res, next) => { let strategy = null try { - strategy = k8sHelpers.getSingleByName(k8sConstants.strategyApi, 'github') - } catch {} + strategy = await k8sHelpers.getSingleByName( + k8sConstants.strategyApi, + 'github' + ) + } catch (error) { + next(error) + } if (!strategy) { const err = new Error('Cannot find strategy') @@ -64,13 +70,15 @@ router.get('/github/callback', (req, res, next) => { return } + const config = JSON.parse(stringHelpers.b64toAscii(provider.spec.config)) + logger.debug(req) const grantCode = req.query.code - const tokenURL = provider.spec.config.tokenURL - const userProfileURL = provider.spec.config.userProfileURL - const clientId = provider.spec.config.clientID - const clientSecret = provider.spec.config.clientSecret + const tokenURL = config.tokenURL + const userProfileURL = config.userProfileURL + const clientId = config.clientID + const clientSecret = config.clientSecret const userInfo = {} fetch(