You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to support loopback-component-oauth2, we need to allow middleware to be executed only for a subset of application paths. By extension, such solution will allow to use different configuration of the same middleware for different paths.
Example: authenticate paths /restricted and /api using the scope demo, authenticate paths /admin using the scope administration.
For route matching, I'm fine with @ritch's proposal with minor tweaks:
app.middleware('auth', authenticators, {
when: function(req, res) { // Not sure if we need async at all
return getBasePath(req.url) === paths[i]);
}
});
app.middleware('auth', authenticators, {
routes: [paths[i]] // not sure if we need to deal with verb too
});
I want to keep this task simple and focused on the paths only. Conditional functions and sub-phases are out of scope, please open a new issue for each of them if you feel they are "a must have" for the initial release.
As for the route matching, I believe my proposal is better, because it is more consistent with the express convention of specifying the path as the first arg and the handler as the second arg, and also with the Node convention of passing the handler function as the last argument.
app.middleware('auth',['/restricted','/api'],authenticator)// compare to expressapp.use(['/restricted','/api'],authenticator)// compare to Nodeemitter.on('auth',handler)
Keeping in mind the request for a generic condition function, the API can be expanded in the future to support different types of the second argument:
Activity
bajtos commentedon Nov 12, 2014
Proposed solutions:
@bajtos
@ritch
raymondfeng commentedon Nov 12, 2014
In addition to paths, I would like to see support for sub phases too. For example,
It will create a
passportphase and register the PhasedRouter using app.middleware('auth', phasedRouterForPassport).See the middleware/route graph for loopback-gateway: https://github.com/strongloop/loopback-gateway/wiki/Middleware-routes-in-loopback-gateway. I would like to use it to validate our api design.
raymondfeng commentedon Nov 13, 2014
For route matching, I'm fine with @ritch's proposal with minor tweaks:
bajtos commentedon Nov 13, 2014
I want to keep this task simple and focused on the paths only. Conditional functions and sub-phases are out of scope, please open a new issue for each of them if you feel they are "a must have" for the initial release.
As for the route matching, I believe my proposal is better, because it is more consistent with the express convention of specifying the path as the first arg and the handler as the second arg, and also with the Node convention of passing the handler function as the last argument.
Keeping in mind the request for a generic condition function, the API can be expanded in the future to support different types of the second argument:
ritch commentedon Nov 13, 2014
I'm fine with @bajtos proposal.
Eventually it would be nice to add:
raymondfeng commentedon Nov 13, 2014
I'm ok with @bajtos's proposal. For paths, I assume the argument is optional and both 'path' and ['path'] are accepted.
bajtos commentedon Nov 14, 2014
The path-to-regexp conversion used by Express is implemented in a standalone module - see https://www.npmjs.org/package/path-to-regexp
Merge pull request #837 from strongloop/feature/scope-middleware-to-path