How to get a Refreshtoken. (Refresh token is valid for 365 days) Salesforce.
This is a sample for getting the refresh token from saleforce.
(1)Login Salesforce
(2)Change Classc UI (I am not sure hot to do this by Lightning Expreience)
(3)”Setup” -> “Build – Create – Apps” -> Click “Create Apps New” Button.
(4)Input parameters as brlow.
(4.1)Connected App Name …. “sample”
(4.2)API Name ….. “sample”
(4.3)Contact Email …. your email address.
(4.4)Check “Enable OAuth Settings”
(4.5)Set “http://localhost” in “Calllback URL”
(4.6)Selected OAuth Scope … “Full access” + “Perform requests at any time(refresh_token,offline_access)..
warning!! this is sample. you should check this permission carefully.
(4.7)Set your salesforce address in “Start URL”
then, “Save” and Copy next form’s “Consumer Key” and “Consumer Secret”
(5)”Setup” -> “Administer – Manage Apps – Connected Apps”
(5.2)select “sample”
(5.1)”Edit Policies”
(5.2)”Refresh token policy” : Set “Expire refresh token after 365 days.”
(6)Input the url bellow on the web broweer which you are currently using(currently accsssing the salesforce(having web session))
https://****.my.salesforce.com/services/oauth2/authorize?response_type=code&client_id=****&redirect_uri=http%3A%2F%2Flocalhost
* Set your salesforce server name.
* client_id …. your “consumer key”
(6.1)You will be confirmed as below message and select “Allow”
(7)you will be redirected to the following url.
http://localhost/?code=*****
so, save the code.
(8)write a shell as below.
#!/bin/sh CLIENT_ID="consumer key" CLIENT_SECRET="consumer secret" SERVER="yourserver****.my.salesforce.com" CODE="the code you got at (7)" #GET REFRESH TOKEN curl -X POST https://$SERVER/services/oauth2/token -d "grant_type=authorization_code" -d "client_id=$CLIENT_ID" -d "client_secret=$CLIENT_SECRET" -d "code=$CODE" -d "redirect_uri=http%3A%2F%2Flocalhost"
execute the shell above, you can get the response as below.
{"access_token":"***","refresh_token":"***","signature":"****","scope":"refresh_token full","id_token":"","instance_url":"https://***.my.salesforce.com","id":"https://login.salesforce.com/id/******","token_type":"Bearer","issued_at":"*****"}