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
PatlatusPatlatus 

Integration SalesForce with Heroku

My question is following.
I am trying to follow "Integration Workbook" from SalesForce, and I have problems with OAuth.
It seems I am missing something important but I can't understand what it is exactly.
So, when I try to access external java heroku callout application http://bdovhan-sfjavaco-advanced.herokuapp.com/orderui I see error
"redirect_uri must match configuration"
despite I have been steps from Integration Workbook.

 

 
 
which shows
 
error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration
So, the book says I should go to "Develop\Remote Access". When I go there, I see page
Remote Access
 
Remote Access Objects have been moved to Applications. You'll be redirected to that page in five seconds, or you can click Take Me There to go now. 

 
which redirects me to  Create\Apps page.
 
So I created there new "Connected app" with OAuth Settings
OAuth Settings
Consumer Key
3MVG99qusVZJwhskauq_mFaTDmKNd6sj0K1H.A3yHEU9NDt8RrFK9tUOHoo3d_cCTozj.THYcUC8DuGyh4Udx
Consumer Secret
608214169699987470
Selected OAuth Scopes
Full access (full)
Callback URL
https:/bdovhan-sfjavaco-advanced.herokuapp.com/_auth

which I have copied to heroku.

 

So, what is wrong?

SamReadySamReady
Did you set up your environment variable for redirect_uri with an https://?
PatlatusPatlatus

How can I configure redirect_uri?

There is nothing about that in workbook.
I see in request redirect_uri is equal to "https%3A%2F%2Fbdovhan-sfjavaco-advanced.herokuapp.com%2F_auth" which is competely the same as in configuration "https:/bdovhan-sfjavaco-advanced.herokuapp.com/_auth"
h0llyh0lly

I have been having the same problem with precious little response from anyone. Did you manage to resolve the issue?

SamReadySamReady

Based off of the code above, it looks like the URL that was encoded had https:// with two slashes, where the configuration only had one slash.

 

h0lly are you sure that your redirect url is the same (verbatim) as your callback? Also, if you just created a connected app sometimes it takes 5 or so minutes to propogate.

h0llyh0lly

I am using the url specified in the Callback Url within the App settings (and it has the full https://.....). This info is just below the "Consumer Secret".

 

The documentation at  www.salesforce.com/us/developer/docs/api_rest/api_rest.pdf  specifies that the redirect_url is the Callback Url. I do not see anywhere else where a redirect url is specified.

 

I am using the developer edition so I don't know if that is the problem. The developer edition allows you to create one Connected App.

 

I investigated further and this is the error message in detail:

 

error "error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration" string

SamReadySamReady

The callback url that you specify in your connected app should also be an environment variable that you create within the app that you are connecting. If it were a hybrid application, the URL it asks for when you setup your app simply needs to be the same, but its not technically a callback URL since your app lives on the phone not the web. If you are connecting to an external web application (for example one living on heroku) you need to create environment variables to your application either in your code (hardcoded) or as variables that you then set in the command line. 

 

In order for the OAuth flow to work, typically you need to specify your consumer key and callback url (aka application url, etc). Here's an example from Heroku on how to set config vars via command line: https://devcenter.heroku.com/articles/config-vars. 

 

Here's a tutorial setting up a web app deployed to Heroku with a connected app. It takes about 5-10 minutes to walk through from start to finish: http://www2.developerforce.com/en/mobile/getting-started/html5#backbone

 

I always use a developer edition org, and do not think that is why you are getting issues.

h0llyh0lly

Thanks for that but I think we're on different wavelength, probably because my problem doesn't directly relate to Heroku but the error message is the same.

 

I am trying to connect directly to Chatter api using the callback url created in the setup of the Connected App along with the Consumer Key.

 

It indicates on page 6 of http://www.salesforce.com/us/developer/docs/api_rest/api_rest.pdf the url to request and the parameters to pass.

 

Is your response still applicable to this scenario?

thanks

SamReadySamReady

What I was referring to was a specific use case on Heroku, but the OAuth flow is the same. In your external app tapping in with the the Chatter API you'll need to setup the callback URL in your application as a variable for the OAuth flow. 

 

Did you setup the redirect_url to be identitcal to the callback URL? Please paste the error link here along with the callback url/redirect url. Thanks!

h0llyh0lly

trying each of the following urls

 

https://login.salesforce.com/services/oauth2/authorize

https://test.salesforce.com/services/oauth2/authorize (I thought it should be this as it is a developer edition)

also tried

https://subdomain name.my.salesforce.com/services/oauth2/authorize (which was created within the Developer setup)

 

 

It requires: response_type, client_id and redirect_url

 

where 

response_type = code

client_id is the consumer key (from the settings in my app)

redirect_url is the redirect url  (from the settings in my app, or Callback URL as it is titled in the setup)

 

so I am passing these as parameters in the url

 

I instantiate a web request:

 var webRequest = (Http WebRequest)WebRequest.Create(uri);

 

where uri is the url with params

 

I've set the webRequest.Method = "GET" 

 

and finally the response

 

var webResponse = (HttpWebResponse)webRequest.GetResponse();

 

at which point I get 

error "error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration" string

 

 

The callback url (or redirect_url as it specifies in the documentation) is typed correctly with https:// )

The callback url is a path within https://subdomain name.my.salesforce.com/ but the documentation states login.salesforce.com or test.salesforce.com

 

thanks

 

 

 

PatlatusPatlatus

Hello, h0lly, actually I had one slash instead of two slashes in my configuration. However, after fixing this, I still had some other error, possibly in java example application or with some settings.

Piyush GuptaPiyush Gupta
Hi,

heroku config:add OAUTH_CLIENT_KEY=PUBLICKEY OAUTH_CLIENT_SECRET=PRIVATEKEY

here PrIVATEKEY is Consumer Secret not Consumer Key