Skip to content

Commit

Permalink
fix(github): fix github enterprise authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
lucabertelli committed Oct 24, 2023
1 parent 6a276b1 commit 2873f65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ assets/*
*.txt
sample.json
.env
.test/
.test/
.vscode/launch.json
22 changes: 15 additions & 7 deletions controllers/auth/read.auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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')
Expand All @@ -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(
Expand Down

0 comments on commit 2873f65

Please sign in to comment.