[SalesForce] Access token generation through curl

Org: Developer org.
I faced a strange issue. I was generating the access token by providing client id, client secret, username and password.
I used 2 following cURL commands :

  1. curl https://login.salesforce.com/services/oauth2/token -d “grant_type=password” -d "client_id=--client_id--" -d "client_secret=--client_secret--" -d "username=rohit_kapoor@persi.com" -d "password=pwd" .

Result : {"error":"unsupported_grant_type","error_description":"grant type not supported"}

  1. curl -d "username=rohit_kapoor@persi.com" -d "password=pwd" -d "client_id=--client_id--" -d "client_secret=--client_secret--" -d "grant_type=password" https://login.salesforce.com/services/oauth2/token

Result (success) :

{"access_token":"token","instance_url":"https://ap1.s
alesforce.com","id":"https://login.salesforce.com/id/...","token_type":"Bearer","issued_at":"1441611103702","signature":"..signature.."}

Could anyone please explain why placing the SFDC url (https://login.salesforce.com/services/oauth2/token) at the end result in generation access token.

Kindly note: security token is not appended with password while generating access token as Developer org does not have this option (another strange thing)

Best Answer

you are giving the Callback url befor the user is authorised to access his her salesforce account. Callback URL in salesforce is nothing but what Salesforce will callback with once the user authorizes access to his/her Salesforce account. Provide callback url as https://ap1.salesforce.com/services/oauth2/token

so giving the callabck url after the user is authorised provides the access token and the other information

Related Topic