Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My understanding is that you can use the tokens to log in or to hit arbitrary pages that need authentication, even with cURL. If you look in <code>config/initializers/devise.rb</code>, there should be a line that says something like:</p> <pre><code>config.token_authentication_key = :auth_token </code></pre> <p>Whatever the name of the <code>token_authentication_key</code> is should match what you put as the query or form parameter in your request. You used <code>authentication_token</code> in your example, not sure if you changed devise.rb to match that or not.</p> <p>If you want to figure out how things are working internally, I would try <code>git clone git://github.com/plataformatec/devise.git</code> and search for the methods you need clarification of.</p> <p>Here are some sample cURL requests (I made a custom Users::SessionsController that extends Devise::SessionsController and overrides the create method to handle JSON.)</p> <pre><code>class Users::SessionsController &lt; Devise::SessionsController def create resource = warden.authenticate!(:scope =&gt; resource_name, :recall =&gt; "#{controller_path}#new") set_flash_message(:notice, :signed_in) if is_navigational_format? sign_in(resource_name, resource) respond_to do |format| format.html do respond_with resource, :location =&gt; redirect_location(resource_name, resource) end format.json do render :json =&gt; { :response =&gt; 'ok', :auth_token =&gt; current_user.authentication_token }.to_json, :status =&gt; :ok end end end end </code></pre> <p>And then the cURL requests I gave:</p> <pre><code>curl -X POST 'http://localhost:3000/users/sign_in.json' -d 'user[email]=example@example.com&amp;user[password]=password' -&gt; {"response":"ok","auth_token":"ABCDE0123456789"} curl -L 'http://localhost:3000/profile?auth_token=ABCDE0123456789' -&gt; got page that I wanted that needs authentication </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload