tillre / cores-hapi Goto Github PK
View Code? Open in Web Editor NEWhapi cores resource api
License: Other
hapi cores resource api
License: Other
Hi Till,
I'm coming to grips with the permissions side of cores-hapi and have the basic CRUD actions working, i.e.
permissions: {
Resource: {
load: true,
create: true,
update: true,
destroy: true,
views: true
}
}
However, I'm not quite sure how to handle allowing users to only update their own documents, i.e. by storing their user id as a document property and then only allowing update or destroy actions if this matches the id of the authenticated user.
If I understand cores-hapi correctly, this level of control is not built in, so presumably would need to be extended to support this? Am I correct in assuming that, and if so, do you have any suggestions as how to do this. Or have I overlooked something fundamental.
Any thoughts or ideas appreciated :)
Regards, Rob
Hi Till,
I've added authentication to my API server and noticed that I was getting 401s in my Angular app when retrieving /_index
. As Hapi only authorises authenticated users, I overcame this by changing the auth mode to allow 'try' in /cores-hapi/lib/create-api.js
, e.g.:
// GET resources index
{
method: 'GET',
path: basePath + '/_index',
config: {
auth: {
mode: 'try'
},
handler: function() {
this.reply(index);
}
}
},
My patch is forked here: iotaweb@42b16e9
I didn't want to submit a PR as I wanted to make sure it wasn't something I had overlooked. Naturally, this wouldn't apply if the API is not secured (but 'try' mode allows for anonymous or authenticated users).
Regards, Rob
OK, I hope this is my last question about authorisation :)
How would I go about providing anonymous to some resources, while securing others. Or indeed, only protecting some actions, e.g. create, update and destroy whilst allowing anonymous access to load and views.
As your library takes care of the route configuration, I'm not sure how to handle these exceptions. An thoughts or ideas much appreciated.
Cheers, Rob
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.