I am trying to wrap my brain around building an express.js / node.js based REST API. I have a couple of questions...
Do I NEED token based / oauth 1 or 2 security for my api if I'm only concerned about a web application right now (not necessarily phone apps)
Are there any resources to learn how to build this from scratch? I've read literally the first 3 pages of googling "rest api with oauth2 authentication express.js" and i'm still not grasping it.
Its good that you want to do a REST API in node. Its really good in building API based request.
For your question:
But if your data is sensitive, such as private user data, then you need to put some sort of security layer on your API. Also, using OAuth or other token based security can help you build a better permission checking across your user base.
http://www.slideshare.net/MindfireSolutions/oauth-and-rest?qid=09a7d224-78bb-4b47-8957-3f0a0ce809a4&v=qf1&b=&from_search=3
For more detailed info about OAuth: https://www.rfc-editor.org/rfc/rfc6749
Again, once you understand the workflow of OAuth, you can implement it easily. :P
It does not depend if you use your REST server for web applications or for any other clients. If the service available in internet you should consider any client application as an "enemy". I mean you should not rely on any "trusted" client app, you should always perform authentication, if the client gets secured resource. Is the resource secured, it depend on your app. I prefer to use oauth2 in both cases. If resource is not secured, I use Client Credentials (https://www.rfc-editor.org/rfc/rfc6749#section-1.3.4), if it's secured I use Access Token (https://www.rfc-editor.org/rfc/rfc6749#section-1.4). It allows you to keep in the same tech, and easily change the things in the future, if it's needed. Based on my personal experience, I created module oauthifizer (https://github.com/vedi/oauthifizer). It's actually a wrapper around passport.js, which makes it more friendly in those particular cases.
You can have a look at this article: http://aleksandrov.ws/2013/09/12/restful-api-with-nodejs-plus-mongodb/. Again, you can consider to try restifizer (https://github.com/vedi/restifizer) - another module, which allows you to create RESTful services significant faster. And there is short example for it: https://github.com/vedi/restifizer-example
Hope it will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With