Question: is there benefit, for app.resource() style REST or in general, in having a declarative authorization middleware?
(regrets if this double-posted; it didn't appear to go through to Google Groups correctly the first time)
Express-resource is essentially a convenience function:
app.resource('user',userHandler)
is just a much shorter form of
app.get('/user',userHandler.index);
app.get('/user/:user',userHandler.show);
//etc.
The problem with app.resource() is that it doesn't give any route-specific middleware, which makes security constraints difficult. E.g. if I only want each person to view their own user, and only admins can list all users, nothing I can do in app.resource().
To solve this, I have the seed of a middleware that would let you do:
app.use(authorizer('./path/to/file.json'));
app.use(app.router);
The json config file looks like:
{
rules:[
// [verb,path,default,condition]
['GET','/user','deny','req.user && req.user.roles.admin === true'],
['GET','/user/:user','deny','req.user && req.user.roles.admin === true ||
req.user.id === :user'],
// etc.
]
}
It gets more flexible than that, but is essentially declarative authorization for all paths.
1) Would people find this useful (with app.resource() REST or generally)?
2) With this middleware, you need to list out all verbs and routes all over again. Does this eliminate all the benefit of app.resource() in the first place?