forked from ExpressGateway/express-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ExpressGateway#890 from ravikp7/lazy-load-policies
feat: lazy load and hot reload for policies
- Loading branch information
Showing
14 changed files
with
138 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const passport = require('passport'); | ||
const BasicStrategy = require('passport-http').BasicStrategy; | ||
const services = require('../../services/index'); | ||
const authService = services.auth; | ||
|
||
module.exports = function registerBasicStrategy() { | ||
passport.use(new BasicStrategy({ passReqToCallback: true }, authenticateBasic)); | ||
|
||
function authenticateBasic(req, clientId, clientSecret, done) { | ||
let credentialType, endpointScopes, requestedScopes; | ||
|
||
if (req.egContext && req.egContext.apiEndpoint && req.egContext.apiEndpoint.scopes) { | ||
endpointScopes = req.egContext.apiEndpoint.scopes && req.egContext.apiEndpoint.scopes.map(s => s.scope || s); | ||
credentialType = 'basic-auth'; | ||
} else { | ||
credentialType = 'oauth2'; | ||
if (req.query && req.query.scope) { | ||
requestedScopes = req.query.scope.split(' '); | ||
} else if (req.body && req.body.scope) { | ||
requestedScopes = req.body.scope.split(' '); | ||
} | ||
} | ||
return authService.authenticateCredential(clientId, clientSecret, credentialType) | ||
.then(consumer => { | ||
if (!consumer) { | ||
return done(null, false); | ||
} | ||
return authService.authorizeCredential(consumer.id, credentialType, endpointScopes || requestedScopes) | ||
.then(authorized => { | ||
if (!authorized) { | ||
return done(null, false); | ||
} | ||
|
||
consumer.authorizedScopes = endpointScopes; | ||
|
||
return done(null, consumer); | ||
}); | ||
}) | ||
.catch(err => done(err)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.