JSON Web Token with Devise

Noman Ur Rehman picture Noman Ur Rehman · Mar 21, 2016 · Viewed 8.1k times · Source

I hope this does not count as an opinionated question. I just need to be pointed in the right direction.

I am modifying the Devise gem to work purely with JSON. I have had no problems with the registration, confirmation, re-confirmation, locking so far.

However, while working with the sign in, I dug deeper and understand that the default Devise sign in strategy uses Warden as it has to do with sessions and Rack authentication.

I understand JWT contains all the information in itself and does not need sessions.

So if I strip the default Devise strategy of everything and simply return a JWT on success and errors on error, would that be the right approach?

Am I missing something?

Answer

Waiting for Dev... picture Waiting for Dev... · Mar 2, 2017

In order to use JWT with devise, I recommend to not monkey patch devise and instead use a tool others can audit and test.

For this reason, I developed devise-jwt. It does zero monkey patching and leverages warden, which is the authentication library below devise. You can also read more about it in this post I wrote: A Secure JWT Authentication Implementation for Rack and Rails

Hope it helps