Note that there are some explanatory texts on larger screens.

plurals
  1. POHow Can I Tell Controller Specs to Use the Signed OAuth Request
    primarykey
    data
    text
    <p>I am building a 2-Legged OAuth provider for my api. Everything is hooked up properly and I can make signed calls from the rails console. The problem I have is that I am having trouble integrating OAuth into the <code>controller_spec</code>.</p> <p>Here is an example of a working call on my server:</p> <pre><code>coneybeare $ rails c test Loading test environment (Rails 3.2.0) rails test: main &gt;&gt; consumer = OAuth::Consumer.new("one_key", "MyString", :site =&gt; [REDACTED]) # =&gt; #&lt;OAuth::Consumer:0x007f9d01252268 @key="one_key", @secret="MyString", @options={:signature_method=&gt;"HMAC-SHA1", :request_token_path=&gt;"/oauth/request_token", :authorize_path=&gt;"/oauth/authorize", :access_token_path=&gt;"/oauth/access_token", :proxy=&gt;nil, :scheme=&gt;:header, :http_method=&gt;:post, :oauth_version=&gt;"1.0", :site=&gt;[REDACTED]}&gt; ruby: main &gt;&gt; req = consumer.create_signed_request(:get, "/api/v1/client_applications.json", nil) # =&gt; #&lt;Net::HTTP::Get GET&gt; ruby: main &gt;&gt; res = Net::HTTP.start([REDACTED]) {|http| http.request(req) } # =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt; ruby: main &gt;&gt; puts res.body {"client_applications":[{"id":119059960,"name":"FooBar1","url":"http://test1.com"},{"id":504489040,"name":"FooBar2","url":"http://test2.com"}]} # =&gt; nil </code></pre> <p>And here is what I am doing in my controller tests:</p> <pre><code>require 'oauth/client/action_controller_request' describe Api::ClientApplicationsController do include OAuthControllerSpecHelper … … it "assigns all client_applications as @client_applications" do consumer = OAuth::Consumer.new("one_key", "MyString", :site =&gt; [REDACTED]) ActionController::TestRequest.use_oauth=true @request.configure_oauth(consumer) @request.apply_oauth! puts "request.env['Authorization'] = #{@request.env['Authorization']}" get :index, {:api_version =&gt; 'v1', :format =&gt; :json} response.should be_success # Just this for now until I can get authorization, then proper controller testing end end </code></pre> <p>The output of that test:</p> <pre><code>request.env['Authorization'] = OAuth oauth_consumer_key="one_key", oauth_nonce="gzAbvBSWyFtIYKfuokMAdu6VnH39EHeXvebbH2qUtE", oauth_signature="juBkJo5K0WLu9mYqHVC3Ar%2FATUs%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1328474800", oauth_version="1.0" 1) Api::ClientApplicationsController GET index assigns all client_applications as @client_applications Failure/Error: response.should be_success expected success? to return true, got false </code></pre> <p>And the corresponding server call from the rails log:</p> <pre><code>Processing by Api::ClientApplicationsController#index as JSON Parameters: {"api_version"=&gt;1} Rendered text template (0.0ms) Filter chain halted as #&lt;OAuth::Controllers::ApplicationControllerMethods::Filter:0x007f85a51a8858 @options={:interactive=&gt;false, :strategies=&gt;:two_legged}, @strategies=[:two_legged]&gt; rendered or redirected Completed 401 Unauthorized in 15ms (Views: 14.1ms | ActiveRecord: 0.0ms) (0.2ms) ROLLBACK </code></pre> <p>I just can't figure out why it's not working :/ Am I making an obvious mistake?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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