-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to check for admin auth in dynamic hook? #9
Comments
heya @inator this “isn’t supported” at this point, but you could do it yourself: Parse the bearer token in the incoming request, match it against the CouchDB admin user, if it fails, deny the request. See hoodie-server/lib/server/plugins/api/index.js for how bearer tokens work. |
Thanks @jan! I can read the bearer token from the request object with no problem, but where do I get the current admin user's issued token for comparison? |
@janl - While trying to be resourceful in the absence of your great advise, I hit up the #couchdb IRC channel:
I'm at a bit of a loss on how to pull this off, but I'm thinking that I could use the nodes built in https.request method and somehow inject the cookie headers in a separate request to /_session. Is there some easier way? Is this even relevant as it relates to the use of bearer tokens? |
maybe @michielbdejong can chime in to explain the bearer token magic |
I think: For normal requests that go to CouchDB, the bearer token on an incoming request is made into a cookie at the hapi layer, before the request gets passed on to CouchDB. and if CouchDB sets a cookie on the response, then this is made into a bearer token at the hapi layer. The bearer tokens are only relevant for the communication between the client and hapi. For the communication between hapi and CouchDB, the cookie is used. To restrict a database action only to admins, you should keep that entirely inside CouchDB, I think. Your API layer can just pass on the request, and if there is no valid logged-in user then CouchDB will reject it. To restrict an action that would not normally go to CouchDB, sounds like you would have to make a request to CouchDB first, yes. This was already true before the switch to bearer tokens: only CouchDB knows if a token/cookie is a valid session, the hapi layer by itself has no persistence of that info. At least that's how I remember it. :) HTH! |
@janl ar anyone who might know:
How might I ensure that my plugin dynamic.js hook "api" can only be executed by an authenticated admin? I'd like to allow for some POST/GETS from the admin dashboard only.
The text was updated successfully, but these errors were encountered: