You need to sign in to do that
Don't have an account?
Having trouble getting Access Token with username/password
Hi All,
Not sure what I'm missing. I've been looking at this for a while and can't figure out what I'm doing wrong. I'm trying to get a token that doesn't expire so that I can make calls to the REST api. Here are some examples of my requests and responses.
None of these have worked. What am I doing wrong?
curl -F "grant_type=password&client_id=my_remote_access_consumer_key&client_secret=my_remote_access_consumer_secret&username=dustin@example.com&password=my_password" https://na9.salesforce.com/services/oauth2/token
response: {"error":"unsupported_grant_type","error_description":"grant type not supported"}
curl -d "grant_type=password" -d "client_id=my_remote_access_consumer_key" -d "client_secret=my_remote_access_consumer_secret" -d "username=dustin@example.com" -d "password=my_password" https://na9.salesforce.com/services/oauth2/token
response: {"error":"invalid_grant","error_description":"authentication failure - Failed: API security token required"}
curl -d "grant_type=password&client_id=my_remote_access_consumer_key&client_secret=my_remote_access_consumer_secret&username=dustin@example.com&password=my_password" https://na9.salesforce.com/services/oauth2/token
response: {"error":"invalid_grant","error_description":"authentication failure - Failed: API security token required"}
Here's my attempt to use the SOAP login() method:
curl https://na9.salesforce.com/services/Soap/u/21.0 -H "Content-Type: text/xml; charset=UTF-8" -H "SOAPAction: login" -d @soap.txt
where soap.txt is:
response:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Client</faultcode>
<faultstring>Element type "env:Envelope" must be followed by either attribute specifications, ">" or "/>".</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
I don't need to know how all of these work, just one.
Thanks in advance for the help.
Dustin
This is quite strange. Any chance I could Private Message you and give you my username/password?
This is just a developer account that I'm doing this with. It must be something wrong with how I've configured the app in the Remote Access setup screen.
Here is my remote access setup screen with some of the secret items blocked out:
http://bit.ly/kOj6kj
I found the solution.
If you go all the way down on this page:
http://wiki.developerforce.com/index.php/Digging_Deeper_into_OAuth_2.0_at_Salesforce.com#Token_Refresh
You'll see that it says:
password
The API user's Salesforce.com password. If the client's IP address has not been whitelisted in your org, you must concatenate the security token with the password.
Ugh.
So, you have to log in, go to Setup > My Personal Information > Reset My Security Token.
Then, it will email you your security token.
Then, you take that security token and append it to your password in the curl request.
So, this works:
curl -d "grant_type=password" -d "client_id=my_remote_access_consumer_key" -d "client_secret=my_remote_access_consumer_secret" -d "username=dustin@example.com" -d "password=my_password+security_token" https://na9.salesforce.com/services/oauth2/token
For the record, that was buried and very poorly documented as far as I can tell.
This is from the Reset Security Token interface:
Hi Simon,
I was working on an issue with Salesforce and oAuth using the password flow.
Your first reponse caught my eye. I was just curious if you were using a dev instance or a production instance?
Whenever I attempt to use login.salesforce.com... as opposed to my naX.salesforce.com, I result in a {"error":"unknown_error","error_description":"retry your request"} message. Your respose was the first that seemed to indicate someone had it working with simply login.salesforce.com
Thanks in advance!
I had same trouble and got resolved by resetting security token.
The place of resetting security token had found on the menu on upper right coner which has links like this > <logged user> | Setup | Help
From those links select,
<Logged Username > My Settings > Personal > Reset My Security Token
instead of the place Setup > My Personal Information > Reset My Security Token
which cannot be locate for me.
I'm new to salesforce and i assumed there has been some UI changes make these difference.
Hope this would help someone like me. :)
Thanks
DarRay
grant_type=password, this is constant. Don't replace password with any password. keep it as it is. So this is what you have to run.
curl -d "grant_type=password" -d "client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -d "client_secret=5014606373847379843894729400" -d "username=you@gmail.com" -d "password=mypassword1234rvloVsadfafsayTKwUvvnkv9uP" https://na9.salesforce.com/services/oauth2/token