I have a (I hope) quick question regarding Authorization in Keystone: it seems like the "User" object is a core dependency in the framework. I'd like to side-step it completely but there doesn't seem to be a way to get the application functional without it.
I've run a basic bypass here:
keystone.init({
//...
'auth': (req, res, next)=>{
if(Roles.has(Roles.Admin, Roles.Keyston)){
next();
} else {
throw "403"; //Terminate
}
},
'user model': 'User',
//...
})
Which results in:
Sorry, an error occurred loading the page (500)
snip\KS2\node_modules\keystone\templates\layout\base.jade:80
> 79| a(href='/keystone/' + User.path + '/' + user.id)= User.getDocumentName(user)
80| | .
81|
82| //- Common
item.get is not a function
As a result it expects the user object to exist on the request (even though I'm using my own authentication method). If I disable authentication completely it seems fine and I can protect the route with some middleware, but this seems like fairly buggy behavior.
Is the "User" object actually a dependency in the framework or is it basically there for convinience? Removing the model
//'user model' : 'User'
crashes Keystone
Sorry, an error occurred loading the page (500) Unknown keystone list undefined).
I'm fairly certain the former error is related to the "User Object" on the request being set to something silly and thus the Jade template blows up. Is it possible to decouple this User object from the framework? If it isn't is it possible to set this object so that I can continue using passport.js
for primary authentication?
I'm particularly interested in this topic as I'd like to implement Role Based Authentication in the Keystone.js administration module and without more information on how this works/ideas for workarounds I don't have a jumping off point.
(**EDIT The error exists even with auth set to false)
Sorry, an error occurred loading the page (500)
...snip\KS2\node_modules\keystone\templates\layout\base.jade:78
76| if User && user
77| | Signed in as
> 78| a(href='/keystone/' + User.path + '/' + user.id)= User.getDocumentName(user)
79| | .
80|
81| //- Common
item.get is not a function
Exits even with auth: false
as I have a "user" object that is turning up null and crashing the template.
EDIT #2 I've created a patch that solved the crash when user authentication is turned off, it doesn't really answer the question but it makes the application usable once again without depending on Keystone.js for authentication (which was a CRITICAL requirement for this CMS).