2

I have set up a test application on my developer instance of Salesforce. I have a client_id, client_secret and I have the necessary security token appended to my password.

I am trying to authenticate using the password grant type. When I send the following http request (using Postman) to

https://na16.salesforce.com/services/oauth2/token

POST /services/oauth2/token HTTP/1.1
Host: na6.salesforce.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded

grant_type=password&client_id=XXXXX&client_secret=YYYYY&username=my.name%40mydomain.com&password=PWDSECURITYTOKEN

I receive the following JSON result:

{
    "error_description": "authentication failure",
    "error": "invalid_grant"
}

Any idea what I can look at to debug this? Am I missing something?

Thanks!

1
  • I want to thank everyone for their help. I actually did get this to work, but unfortunately, I had compensating errors, so there really wasn't one cause. In the end, all the parameters were correct, but the URL I was using was incorrect. I think my major mistake was not using URL form encoded at first.
    – psparago
    Mar 15, 2015 at 23:29

2 Answers 2

1

I would check to make sure that the user you are logging in with has access to the connected app that you created, and that the connected app includes the "access to data via the web" scope enabled. Also, make sure you put the elements in the form section of Postman, and not in the Header. For the authentication flow, you shouldn't need any headers.

7
  • Thank you for the response. Still no luck. Postman says it's sending a form and the body has the parameters (see above), so I think that's in order. I did edit the test app and changed permitted users to all users may self-authorize and set the IP Relaxation to Relax IP restrictions. I do not have a start web url or start mobile url. Is that bad?
    – psparago
    Mar 11, 2015 at 21:44
  • 1
    Don't use the self authorize option, that assumes there will be a UI interaction for the user to "accept" the authorization request. Set it to "pre-authorized by Admin" (whatever that option is called), and make sure the profile of your test user has the Connected App listed in their profile.
    – JimRae
    Mar 11, 2015 at 21:46
  • Thank you again. As I said, total newbie :-). I am not using a test user. I am trying to authenticate me (using the username and password I use to get into the developer site instance) and I am the administrator of the site (I assume, since I created it) so I think I would have access and privilege to the app. Do I need to include any specific profiles?
    – psparago
    Mar 11, 2015 at 21:55
  • You need 5o edit the system administrator profile, and add your connected app to the connected apps assigned to the profile.
    – JimRae
    Mar 12, 2015 at 2:41
  • In 'Connected App Detail', I have assigned several profiles to my app. System Administrator is one of the profiles I assigned to the app. Is this correct? Is there some other place I need to make this link? I tried editing the administrator profile and did not see a way of associating my app with that profile. Once again, thank you for the assistance.
    – psparago
    Mar 12, 2015 at 17:39
0

You can read below document for correct oauth links

https://www.salesforce.com/us/developer/docs/api_rest/Content/intro_understanding_oauth_endpoints.htm

If you are using Prod your oauth end point will be as below

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

If you are on the Sandbox ,your oauth end point will be as below

https://test.salesforce.com/services/oauth2/token

Hope correcting end points resolves your issues

1
  • Thank you for the quick response. Unfortunately, changing the URL did not solve the problem.
    – psparago
    Mar 11, 2015 at 21:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .