title: Pass Authenticity token through http header
body: <p>I have a rails application that uses a token to authenticate the user. Currently I am passing the token as params. I would like to change this. I believe it is possible to pass it through html header. I dont understand how to use <code>authenticate_or_request_with_http_token do |token, options|</code>.
  My rails app is actually a server for my iphone client. I things I dont understand are:</p>
  
  <ol>
  <li><p>I know <code>options</code> is nonce but how will that work out between my client and server?</p></li>
  <li><p>How do I actually use this in my server code.</p></li>
  <li><p>I can use <code>authenticate_or_request_with_http_token do |token, options|</code> to check for token in the the header but how do I insert it into the header once a session is created successfully.</p></li>
  </ol>
  
  <p>Here is my server Sessions Controller:</p>
  
  <pre><code>def create
  if @user &amp;&amp; @user.authenticate(params[:password])
   # @token = @user.auth_token
   @user.auth_token = SecureRandom.hex 
   @user.save
      respond_to do |format|
          format.json {render :json =&gt; {:status =&gt; "200", :message =&gt; "Logged in successfully", :auth_token =&gt; @user.auth_token}}
      end
  else
      respond_to do |format|
          format.json {render :json =&gt; {:status =&gt; "401", :message =&gt; "wrong credentials"}}
      end
  end
    end
  
    def destroy
      if(@user)
        @user.auth_token = ""
        @user.save
        respond_to do |format|
           format.json {render :json =&gt; {:status =&gt; "200", :message =&gt; "logged out successfully"}}
        end
      else
        respond_to do |format|
           format.json {render :json =&gt; {:status =&gt; "401", :message =&gt; "No User"}}
        end
     end
    end
  
  def user
    @user = User.find_by_auth_token(params[:auth_token])
  end
  </code></pre>