1

I know this must have been posted here and I've tried the solutions I've searched across the web but I am still getting the error {"error":"invalid_grant","error_description":"authentication failure"} when I try to perform a cURL request to my dev org.

I've configured the connected app as follows:

  • Relaxed IP Restrictions
  • Allowed users to self authorize

System admin profile:

  • tried to made sure the connected app is added to my profile
  • tried to add my ip on the login ip range just to see and removed it

Built my cURL request from a Mac terminal:

curl -v https://ap15.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=xxxxx" -d "client_secret=xxxxx" -d "username=xxxxx" -d "password=xxxxx"

Or (password with security token)

curl -v https://ap15.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=xxxxx" -d "client_secret=xxxxx" -d "username=xxxxx" -d "password=xxxxxSECURITYTOKEN"

Or (variations of the domain)

curl -v https://login.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=xxxxx" -d "client_secret=xxxxx" -d "username=xxxxx" -d "password=xxxxx"

curl -v https:///services/oauth2/token -d "grant_type=password" -d "client_id=xxxxx" -d "client_secret=xxxxx" -d "username=xxxxx" -d "password=xxxxx"

I tried to incorrectly send a wrong client secret and it would say invalid client credential so I verified that those were correct and that it fails on authentication without any clear message. There isn't anything I can find around in salesforce looking for those and I would like to ask if there's anyone who got around this issue.

I've tried sending and was able to get response from POSTMAN as well but for cURL it does not work. I'm not sure if this is a salesforce issue or a Mac Terminal Issue or any configuration that would need to be made.

Please advise, Thank you in advance!

3
  • Are you adding Security token to your password? It's required to add at the end of the Password for Username-Password flow. Read the NOTE help.salesforce.com/… – ytiq Apr 8 at 4:35
  • one possibility - your password may have some weird symbol which SF doesnt support. Can you try to set password simple(for testing only) - Example Alpha@Beta123 – Ysr Shk Apr 8 at 6:18
  • thank you guys for your response! I was able to fix the issue by changing the "-d" to "--data-urlencode" I think my username / password / client / secret values contain characters that need to be encoded. Also, I tried to do this with a standard user and a community user. The standard user makes use of securty token. The community user attempt fails but that could be because of the lack of security token but that is a different problem. Thank you so much for your inputs – nekmancer Apr 12 at 2:38
1

Happened to me too. I guess it's got to do with encoding, so this format worked for me:

curl --location --request POST 'https://login.salesforce.com/services/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=xxxx' \
--data-urlencode 'password=xxxx' \
--data-urlencode 'client_id=xxxx' \
--data-urlencode 'client_secret=xxxx'
1
  • I was able to try out some solutions and finally had mine work by changing my command from "-d" to "--data-urlencode". Thanks! – nekmancer Apr 12 at 2:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.