How to protect all routes #860
Unanswered
nubianMONK
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Stack:
Front End - Angular 12
|-- Leveraging Angular/MSAL to integrate with Azure AD for authentication
Back End
|-- Node JS V14.17.6
|-- Express 4.17.1
|-- Passport-Azure-AD V4.3.0 (passport-azure-ad is a collection of Passport Strategies to help you integrate with Azure Active
|-- Authentication Strategy - BearerStrategy (Protects APIs and Resources)
Directory)
|-- Passport V0.3.2 (Passport version leveraged by Passport-Azure-AD)
Back End Project Structure (Excerpt shown for brevity)
Root Directory
|-- src
|-- routers(Sub directory that holds all modularized routes per entity in individual .js files e.g. users.js, actions.js)
|--index.js(Application entry point)
I'm looking for a way to protect all my routes/api endpoints, rather than having to apply the passport.authenticate to each route handler within each of the route endpoints which could be "N" number of routes per modularized route .js files as expressed above. I have tried the following below to no avail.
Within the index.js file, i.e. the applications entry point, in which I use e.g. const users = require('./routers/users') and app.use('/api/v1/users', users) to mount my route handlers, I introduced the following app.use(passport.authenticate('oauth-bearer', { session: false })) since passport is a middleware but no joy
Within the modularized route handling files, I tried the following as well: router.all(
'*'
,passport.authenticate('oauth-bearer', { session: false })) based on the express documentation, router.all should apply a middleware or provided function/handler at a path for all request methods and in this case the'*'
should match all paths, but still this only worked for the base path '/' and not others in the file e.g. '/relationships'If anyone can prescribe a way to protect all routes, it will be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions