INVALID_SESSION_ID: Session expired or invalid - Restforce gem - Ruby on Rails - Salesforce API

576 Views Asked by At

I am getting a INVALID_SESSION_ID: Session expired or invalid

I am using Restforce api to intereact with the Saleforce API. I made a connected app in salesforce. I set the Oauth options to: Selected OAuth Scopes
Provide access to your data via the Web (web) Full access (full) Perform requests on your behalf at any time (refresh_token, offline_access) I set Refresh Token Policy: Refresh token is valid until revoked

I got a token. I set up a new Restforce object in Rails.

client = Restforce.new(
oauth_token: ENV['SALESFORCE_OAUTH_TOKEN'.to_s],
instance_url: ENV["SALESFORCE_INSTANCE_URL".to_s],
api_version: '26.0')

It is creating the object with the right client_id and client_secret and instance url but I think whats happening is the values are being saved with an escape character. I'm not sure that that is what it is but I've had a similar problem in the past and I was able to get rid of the "\" character and it worked.

I can't seem to get it to work this time. Here is what I am getting as the client object:

<Restforce::Data::Client @options={:api_version=>\"26.0\", :username=>nil, :password=>nil, :security_token=>nil, :client_id=>\"3MVG91SanXDmR_Aj4EKMmpYG_RTw39x1KA5dhzPc.9A1sNc6Gd9BYnNwVVxf.xVADoh0S9g==\", :client_secret=>\"34679683177007645\", :host=>\"login.salesforce.com\", :oauth_token=>\"tEngAuWGFV9fW6EknyRAf\", :refresh_token=>nil, :instance_url=>\"https://na61.salesforce.com\", :cache=>nil, :authentication_retries=>3, :compress=>nil, :mashify=>nil, :timeout=>nil, :adapter=>:net_http, :proxy_uri=>nil, :authentication_callback=>nil, :ssl=>{}, :request_headers=>nil, :logger=>#<Logger:0x0055a629b489d8 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x0055a629b489b0 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x0055a629b48910 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x0055a629b488e8>>>, :log_level=>:debug}>"

I've changed the the value of the oauth token, client_id and client_secret for security reasons. I've tried chop and strip and some gsub. It doesn't seem to work.

I tried

client.options[:client_secret] = client.options[:client_secret].strip
client.options = client.options.delete ('\\')
client.options[:client_secret] = client.options[:client_secret].chomp

I've tried a few other things can't seem to get it to work. Please help!

0

There are 0 best solutions below