# Token authenctication

**URL:** <https://www.ruby-forum.com/t/token-authenctication/231878>\
**Category:** Rails\
**Created:** [September 3, 2014, 9:56pm UTC](https://www.ruby-forum.com/t/token-authenctication/231878 "2014-09-03T21:56:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [September 3, 2014, 9:56pm UTC](https://www.ruby-forum.com/t/token-authenctication/231878/1 "2014-09-03T21:56:46Z")

</div>

Hi all, i’m building my first project in RoR. And i’m now looking into  
authentication. A lot of the posts online recommended devise so i’m  
looking  
into that.  
I require authentication in a html website and a json api and i’m using  
ruby 1.9.3 and rails 4.1.4. Now I have seen that devise has  
removed TokenAuthenticatable. Is devise still a good option for token  
authentication or are there better options?

I have seen some custom implementations of token authentication with  
devise. But i’m reluctant to use these, security is one of those area’s  
I  
try to prevent hacking together my own code. My users trust me with  
their  
personal information, and I think I should respect that trust by using a  
mature solution, which has the best chance of keeping their data secure.

Just to be clear I’m not running a bank or handling medical data, but  
still  
I don’t want to implement the first snippet of code that I see and risk  
leaking my users data.

Could someone offer me some advise?

Regards,

Sander

---

<div class="post-metadata">

**Author:** ![Sander\_Obdeijn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@Sander\_Obdeijn](https://www.ruby-forum.com/u/Sander_Obdeijn)\
**Post date:** [September 4, 2014, 4:05pm UTC](https://www.ruby-forum.com/t/token-authenctication/231878/2 "2014-09-04T16:05:20Z")

</div>

On Wednesday, 3 September 2014 14:41:30 UTC-4, Sander Obdeijn wrote:

> devise. But i’m reluctant to use these, security is one of those area’s I

Some info on token\_authenticatable, direct from Jose Valim:

> <https://gist.github.com/josevalim/fb706b1e933ef01e4fb6>

A gemified version of it, recently extracted:

> **[GitHub - baschtl/devise-token\_authenticatable: This gem provides the extracted Token...](https://github.com/baschtl/devise-token_authenticatable)**
>
> This gem provides the extracted Token Authenticatable module of devise. It enables the user to sign in via an authentication token. This token can be given via a query string or HTTP Basic Authentication.

I’ve used the Gist version in a production app.

–Matt J.

---

<div class="post-metadata">

**Author:** ![Sander\_Obdeijn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@Sander\_Obdeijn](https://www.ruby-forum.com/u/Sander_Obdeijn)\
**Post date:** [September 4, 2014, 5:20pm UTC](https://www.ruby-forum.com/t/token-authenctication/231878/3 "2014-09-04T17:20:53Z")

</div>

I think you can implement that yourself along with Devise. Since you get  
so much with devise I would do that if it were me.

last time I discussed this with business people, the need for the token  
auth outweighed the security considerations. We ameliorated this by 1)  
Making the token expire 7 days after you generate it, and 2) making it  
automatically expire the moment it is used.

Also, if you send that sh\*t over email then you’re still transmitting it  
in plain-text, which is susceptible to MITM. But the limits we put in  
made us confident this was an acceptable middle-ground.

Then again, if you’re storing celebrities’ naked pictures of themselves,  
you might want to reconsider 😉

-Jason

---

<div class="post-metadata">

**Author:** ![Sander\_Obdeijn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@Sander\_Obdeijn](https://www.ruby-forum.com/u/Sander_Obdeijn)\
**Post date:** [September 4, 2014, 10:18pm UTC](https://www.ruby-forum.com/t/token-authenctication/231878/4 "2014-09-04T22:18:40Z")

</div>

No only my own private ‘au natural’ pictures will be hosted.

I’m looking a the gem, but i can’t find how to request a token after you  
have implemented it. Is there more documention about using the token  
authentication?

Op donderdag 4 september 2014 17:20:05 UTC+2 schreef Jason FB:

---

<div class="post-metadata">

**Author:** ![Sander\_Obdeijn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@Sander\_Obdeijn](https://www.ruby-forum.com/u/Sander_Obdeijn)\
**Post date:** [September 4, 2014, 10:27pm UTC](https://www.ruby-forum.com/t/token-authenctication/231878/5 "2014-09-04T22:27:48Z")

</div>

Sander, devise( [GitHub - heartcombo/devise: Flexible authentication solution for Rails with Warden.](https://github.com/plataformatec/devise) ) + doorkeeper(  
[GitHub - doorkeeper-gem/doorkeeper: Doorkeeper is an OAuth 2 provider for Ruby on Rails / Grape.](https://github.com/doorkeeper-gem/doorkeeper) ) may work well for your  
case.  
Doorkeeper is based on OAuth specs which is pretty solid for token based  
auth. A google search involving both the gems would give you enough  
material to get started. Good luck !
