Skip to content

Commit

Permalink
Merge pull request #30 from appirio-tech/dev
Browse files Browse the repository at this point in the history
parse email from custom claim ("new auth")
  • Loading branch information
sachin-maheshwari committed Nov 18, 2020
2 parents 081138e + 75d096c commit c4ab01f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/middleware/jwtAuthenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = function (options) {
throw new Error('JWT Issuers not configured')
}

let verifier = authVerifier(validIssuers,jwtKeyCacheTime)
let verifier = authVerifier(validIssuers, jwtKeyCacheTime)

return function (req, res, next) {
// check header
Expand All @@ -54,26 +54,32 @@ module.exports = function (options) {
return (key.indexOf('userId') !== -1)
}))
req.authUser.handle = _.find(req.authUser, (value, key) => {
return (key.indexOf('handle') !== -1)
return (key.indexOf('handle') !== -1)
})
req.authUser.roles = _.find(req.authUser, (value, key) => {
return (key.indexOf('roles') !== -1)
return (key.indexOf('roles') !== -1)
})

if (!req.authUser.email) {
req.authUser.email = _.find(req.authUser, (value, key) => {
return (key.indexOf('email') !== -1)
})
}

let scopes = _.find(req.authUser, (value, key) => {
return (key.indexOf('scope') !== -1)
})
if (scopes) {
req.authUser.scopes = scopes.split(' ')

let grantType = _.find(decoded, (value, key) => {
return (key.indexOf('gty') !== -1)
})
if (grantType === 'client-credentials' &&
!req.authUser.userId &&
!req.authUser.roles) {
if (grantType === 'client-credentials' &&
!req.authUser.userId &&
!req.authUser.roles) {
req.authUser.isMachine = true
req.authUser.azpHash= getAzpHash(req.authUser.azp)
req.authUser.azpHash = getAzpHash(req.authUser.azp)
}
}

Expand Down

0 comments on commit c4ab01f

Please sign in to comment.