Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with OAuth 2 Gem
    primarykey
    data
    text
    <p>I have a rails project using <a href="https://github.com/intridea/oauth2" rel="nofollow">https://github.com/intridea/oauth2</a>. In my rails app I have the following code:</p> <p><strong>ApplicationController.rb</strong></p> <pre><code>def facebook_client OAuth2::Client.new(FacebookOauthCredentials::APP_ID, FacebookOauthCredentials::APP_SECRET, :site =&gt; 'https://graph.facebook.com') end </code></pre> <p><strong>FacebookController.rb</strong></p> <pre><code>def facebook_session_create(poster, featured_item) redirect_to facebook_client.web_server.authorize_url(:scope =&gt; 'publish_stream', :redirect_uri =&gt; "http://localhost:3000/facebook/facebook_callback") end def facebook_callback if(params[:code]) begin access_token = facebook_client.web_server.get_access_token(params[:code], :redirect_uri =&gt; "http://localhost:3000/facebook/facebook_callback") access_token.post('/me/feed', "testing #{rand(1000)}") rescue OAuth2::HTTPError =&gt; e render :text =&gt; e.response.body end end end </code></pre> <p>Every time I run this code I get this response:</p> <pre><code>{"error":{"type":"OAuthException","message":"Error validating verification code."}} </code></pre> <p>However, I use the sinatra app supplied in the OAuth2 gem's readme file, it works fine.</p> <pre><code>def client OAuth2::Client.new(FacebookOauthCredentials::APP_ID, FacebookOauthCredentials::APP_SECRET, :site =&gt; 'https://graph.facebook.com') end get '/auth/facebook' do redirect client.web_server.authorize_url( :redirect_uri =&gt; redirect_uri, :scope =&gt; 'publish_stream' ) end get '/auth/facebook/callback' do access_token = client.web_server.get_access_token(params[:code], :redirect_uri =&gt; redirect_uri) begin user = JSON.parse(access_token.post('/me/feed', :message =&gt; "testing # {rand(10000)}")) rescue Exception =&gt; e return e.response.body end user.inspect end def redirect_uri uri = URI.parse(request.url) uri.path = '/auth/facebook/callback' uri.query = nil uri.to_s end </code></pre> <p>I have tried reproducing the steps using irb, but I an http 400 error. I'm not sure if it's for the same reason as the rails app, or if it's because I'm doing a hybrid of console and web browser operation. Any suggestions would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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