function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VarankaushishVarankaushish 

Ruby on Rails REST API Error

While getting response back from SFDC, im getting following error message.

OAuth2::HTTPError in OauthController#callback
Received HTTP 400 during request.

 

I'm using REST API & Rails 3, Apache as reverse proxy & OAuth2 on window machine. 

Help

Thanks

Varun

Best Answer chosen by Admin (Salesforce Developers) 
cloudcodercloudcoder

All Answers

cloudcodercloudcoder

A http resp. Code of 400 indicates a bad request. I suspect you have an error in your http get syntax. Can you paste in the GET request you are making? Im assuming you have already authenticated correctly?

varunkaushish03@gmail.comvarunkaushish03@gmail.com

Yes, you are correct, I'm done with authentication part. Here's the get request.

 

 

  access_token = client.web_server.get_access_token(params[:code], :redirect_uri => "https://localhost/flight/oauth/callback", :grant_type => 'authorization_code')
  @print = access_token.token /*Im able to get token value*/
    user_json = access_token.get('/me') /*Problem starts here*/
    # in reality you would at this point store the access_token.token value as well as 
    # any user info you wanted
    render :json => user_json
    

 

cloudcodercloudcoder

I don't believe the JSON payload of an access token contains a 'me' attribute:

 

{"id":"abc","issued_at":"1296500081178","refresh_token":"mytoken",

"instance_url":"https://prerelna1.pre.salesforce.com","signature":"abc","access_token":"myaccesstoken"}

Aaron VeghAaron Vegh

Hi Varankaushish,

I'm trying to develop a Rails solution using the Ruby OAuth gem; looks like you're doing the same thing. I'm having problems setting up the request token code, and it seems you've gotten further through the process. Can you post your code that does this? For example, I currently have:

 

 

@consumer = OAuth::Consumer.new(api_key, shared_secret,
      { 
        :site => 'https://na1.salesforce.com', 
        :request_token_path => '/services/oauth2/token', 
        :grant_type => 'authorization_code',
        :oauth_version => '2.0'
      })
    
    @request_token = @consumer.get_request_token(
    )
I'm getting 400 not authorized errors. :-(
Cheers,
Aaron.

 

cloudcodercloudcoder
This was selected as the best answer
Aaron VeghAaron Vegh

No, I hadn't seen that, and it seems to have answered all my questions. Thanks very much!

 

Aaron.

Aaron VeghAaron Vegh

While that recipe did help immensely, I'm now hung up on making the actual request, just like the topic of this post. I've responded to a similar thread that is now more recent -- http://boards.developerforce.com/t5/Perl-PHP-Python-Ruby-Development/Ruby-and-OAuth/td-p/242279 -- which contains the details of my issue.