lockit icon indicating copy to clipboard operation
lockit copied to clipboard

Feature request: Token-based auth for REST API

Open colinskow opened this issue 10 years ago • 7 comments

Cookie-based auth doesn't work on Phonegap or Chrome packaged apps. It also leaves vulnerability to CSRF attacks.

A better strategy for an Angular-type SPA is to store a token in LocalStorage: https://auth0.com/blog/2014/01/07/angularjs-authentication-with-cookies-vs-token/

I would like the options to use either json web tokens (which don't require any session store) or a Redis-based token system. This is very easy to implement with Passport.

https://github.com/roblevintennis/passport-api-tokens

If I have some time over the next week I'll send you a pull request.

colinskow avatar Jun 27 '14 07:06 colinskow

Why doesn't cookie based authentication work on PhoneGap? How is the PR going?

zemirco avatar Jul 01 '14 19:07 zemirco

From what I understand cookie auth is a bad practice in general with REST APIs. Malicious scripts from other websites can make calls to the API if a session cookie is set.

What I'm working on is translating the MEAN.io stack into the "CANE" stack. (CouchDB, Angular, Node, Express) It will use PouchDB as the adapter on both client and server, and will be awesome for creating offline applications that sync automatically.

I am going to use your sendmail / forgot password / failed login tracking. However the other changes I want to make will most likely break your API, so it is probably best as a separate project.

MEAN has most of the base code I need. I am going to modify it to use CouchDB as the backend, and use your forgot password / confirm email functionality.

I am also working on a validation package for CouchDB to be able to validate user input similar to Mongoose.

It seems our interests are very much aligned, so perhaps after I get the project off the ground we can work together.

colinskow avatar Jul 02 '14 21:07 colinskow

Where did you get that from?

From what I understand cookie auth is a bad practice in general with REST APIs. Malicious scripts from other websites can make calls to the API if a session cookie is set.

It's simply not true.

Lockit doesn't strive to be a one-size-fits-all solution. It provides user authentication using email/username and password. Lockit is independent from any database and from any frontend framework. It can be part of your W stack (whatever stack (c) myself) though. Therefore I don't think our interests are very much aligned but I'm happy about quality pull requests.

zemirco avatar Jul 03 '14 13:07 zemirco

@zemirco, colinskow is absolutely correct. Cookie authentication is not acceptable in a wide variety of scenarios. If you went so far as to make lockit work with a variety of backends and databases, why wouldn't you also invest the 40 minutes it would take to simply allow cookie or token auth? Or it would probably take a couple hours to simply make the authentication mechanism pluggable to support any type of medium. You've already done the hard work supporting multiple backends and databases, but at the very last mile you are quitting. This is the only reason I'm not using lockit, and I have a couple of friends who told me this was the main drawback of lockit.

jamescam22 avatar Aug 14 '14 12:08 jamescam22

Hi, I am facing this issue for a long time. Although I was able to use local storage approach for basic AJAX calls, I am not able to use it for playing videos in my app. Videos are accessed through URLs which require basic authentication. How can this be achieved?

VipulVikas avatar Jan 06 '15 06:01 VipulVikas

Anyone willing to write a pull request? Otherwise I have to close the issue.

zemirco avatar Jul 23 '15 08:07 zemirco

I ended up building my own Express/CouchDB authentication framework from scratch. It is 100% cookie-free and designed for APIs and single-page apps rather than server-rendered sites. It comes complete with AngularJS bindings and a working live demo. It manages permissions on multiple per-user and shared CouchDB and Cloudant databases.

https://github.com/colinskow/superlogin

But you were right Mirco... Authentication is a lot of work when done by scratch!

colinskow avatar Sep 21 '15 02:09 colinskow