Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting {"error":"invalid_grant","error_description":"authentication failure"} in Salesforce?

I am trying to get the Session ID for my salesforce partialbox.

My Code:

curl https://test.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=definitely the correct client id" -d "client_secret=definitely the correct client secret" -d "[email protected]" -d "password=passandsecuritytoken"

What else I did:

  • Grant full access in my connected app settings
  • Set Ip restrictions to loose ip restrictions
  • "All users can authorize themselfes"
  • Double checked pass, client id, client secret, username

I am still getting the error {"error":"invalid_grant","error_description":"authentication failure"}.

I searched through the SF forums and StackOverflow questions, but I couldn't find any solution for this. Does anyone know, what else could be the problem here?

like image 998
Frederik Witte Avatar asked Dec 08 '15 11:12

Frederik Witte


People also ask

How do I resolve OAuth error in Salesforce?

Revoke the Salesforce App's previous Oauth Tokens: At desktop / laptop Full Site, go to the Advanced User Details, scroll to the Oauth Connected Apps, look for Salesforce for Android / iOS, & click Revoke on those lines. (For more details, please see Manage OAuth-Enabled Connected Apps Access to Your Data.)

How do I fix OAuth error?

When a user tries to login after the session id is expired, the system throws the OAuth error. Solution: Typically, clearing the browser or device cache fixes the problem.

What does Invalid_grant mean?

The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.

How do I enable OAuth settings in Salesforce?

In the Connected Apps section, click New Connected App. In Basic Information, give the app a name, tab through the api field so it will self-populate in the correct format, and enter a contact email for the app. In the API [Enable OAuth Settings] section, select Enable OAuth Settings.


2 Answers

I'm still confused and I don't know exactly what's going on, but I had your same problem and I was able to "fix" it by doing the following.

First, relax IP restrictions for the app.

Manage Apps -> Connected Apps -> (The name of my app)

Then setting "IP Relaxation" to "Relax IP restrictions".

As far as I know, there are not IP restrictions in the sandbox app I'm working with but I'm still new to this, so maybe they are hiding somewhere.

Second, in my curl command which looked a lot like your I left out the security token, so the password field was just the password.

I don't really know if I've solved my problem but I'm getting back an access token and not the "invalid_grant" error.

I plan on doing some additional investigating to figure out what's going on but I figured, while I had this question up I'd make sure this answer was here.

like image 149
Jachin Avatar answered Oct 05 '22 03:10

Jachin


Make sure you have done this steps.

*Apps -> Manage Connected Apps -> (The name of my app) -> Edit Application -> OAuth Polices Then set "Permitted users" to "All users may self-authorize".

*Manage Apps -> Connected Apps -> (The name of my app) Then set "IP Relaxation" to "Relax IP restrictions".

Try to make a curl request with TLS 1.1 enabled

curl -v https://login.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=xxxxxxxxxxXXXXXXXXXX" -d "client_secret=123456789" -d "[email protected]" -d "password=xxxxxxxxxx"

like image 43
Aashish Vivekanand Avatar answered Oct 05 '22 03:10

Aashish Vivekanand