# Question on authenticity tokens

**URL:** <https://discuss.rubyonrails.org/t/question-on-authenticity-tokens/29079>\
**Category:** rubyonrails-talk\
**Created:** [May 7, 2008, 5:31pm UTC](https://discuss.rubyonrails.org/t/question-on-authenticity-tokens/29079 "2008-05-07T17:31:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [May 7, 2008, 5:31pm UTC](https://discuss.rubyonrails.org/t/question-on-authenticity-tokens/29079/1 "2008-05-07T17:31:33Z")

</div>

Does anyone find them useful? I can see them being good in some cases, but I have many exceptions that occur because of expired sessions. I am also not sure if they are really required for pages that require a login to access.

The other place that they cause issues is in javascript requests. I am not using the built-in helpers, and all the javascript exists in separate js files. There is ways to get around this, but they are sloppy.

Is there a way to turn them off?

Here is an example of the the code requires the token. If anyone knows an easy way to solve the problem please let me know.

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [May 7, 2008, 5:47pm UTC](https://discuss.rubyonrails.org/t/question-on-authenticity-tokens/29079/2 "2008-05-07T17:47:26Z")

</div>

It's turned on by the protect\_from\_forgery line in your  
application.rb. The rdoc for that method should you how to have it  
enabled only for some stuff and how to generate the token

Fred

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [May 7, 2008, 6:19pm UTC](https://discuss.rubyonrails.org/t/question-on-authenticity-tokens/29079/3 "2008-05-07T18:19:38Z")

</div>

Hey Fred, Thanks for the info.

As mentioned in the protect\_from\_forgery docs, setting a window.\_token var in the application template file allows for one to easily pass the token.

ex $.post(url, {'\_method': "delete", 'authenticity\_token': window.\_token}, function(){ &nbsp;&nbsp;...

For one small live app I get the occasional exception email notifying me that someones authentication token expired. I have never been able to replicate this exception. Does anyone know if the user is getting slapped with a 422, or are they just being redirected to the login page?

Thanks.

Frederick Cheung wrote:
