Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3346282
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:17:06+00:00 2026-05-18T01:17:06+00:00

I have a Rails site that uses Devise for authentication. I have one page

  • 0

I have a Rails site that uses Devise for authentication. I have one page (PhotosController#create) that needs to authenticate users without cookies. I’m doing this with the :token_authenticatable module of Devise, which authenticates a user if the supplied token matches the token stored on the server side. (See this SO question if you’re curious.)

It’s good policy to expire or change the token after the action is complete. This prevents an attacker from sniffing the token and using it to successfully authenticate as the user. However, in my case, I can’t expire or change the token because the client-side photo uploader uploads multiple photos, each resulting in a separate POST to PhotosController#create. So if I expire the token after a successful create, the second, third, etc. uploads will fail.

Devise modules are specified at the model level (e.g. the User model). I need more granularity than this.

My question is, how do I enable the :token_authenticatable module only for a single action of a single controller? Or, equivalently, how do I disable the :token_authenticatable module for all controllers and actions except for one action?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:17:07+00:00Added an answer on May 18, 2026 at 1:17 am

    As the developer of one devise plugin (devise_rpx_connectable) I’m happy to answer your question.

    TokenAuthenticatable is one Devise strategy, you can read its code here :

    https://github.com/plataformatec/devise/blob/master/lib/devise/strategies/token_authenticatable.rb

    As you can see, each devise strategy has a valid? and/or valid_request? method that is called to determine if the strategy should be enabled. So you can easily override this strategy for your needs, or you can also only override the valid_request? method. Just load this kind of code in an initializer (AFTER devise is loaded of course) :

    module Devise
      module Strategies
        class TokenAuthenticatable < Authenticatable
          private
          def valid_request?
            params[:controller] == "photos" && params[:action] == "create"
          end
        end
      end
    end
    

    I haven’t tested this, I don’t know if that works out of the box but I hope you see the point, if that doesn’t work, use a debugger, or write your own Devise Strategy (see my plugin, it’s easy to understand), etc.

    Moreover, when you use this strategy, the user will be stored in session unless you use the stateless_token option, see :
    https://github.com/plataformatec/devise/blob/master/lib/devise/models/token_authenticatable.rb#L27

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Ruby on Rails site that uses thinking sphinx for searching a
I have a staging Rails site up that's running on MySQL 5.0.32-Debian. On this
I have a site in rails and want to have site-wide settings. One part
I have a rails app that uses heavily js (over 1MB total). I'd like
I have a Rails site, where the content is written in markdown. I wish
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
I'm setting up a rails site that will accept credit cards with ActiveMerchant and
I'm working on a Rails site that connects to an Oracle database, and though
I am creating a web app that uses Rails built-in helper functions to add
So I have been asked to help maintain a website that uses Ruby on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.