Generating a Refresh Token
Perform the following steps in Salesforce to generate the refresh token:
-
In Salesforce, create a New Connected App.
Consider the following as you configure the new connected app:
-
Salesforce generates a Consumer Key and Consumer Secret which can be found in Manage Consumer Details. Retain these for this process as you'll use them for the
client_id
andclient_secret
entries respectively. -
Enter
https://login.salesforce.com/
as the Callback URL. This will be used later in this process.
-
-
Generate an authorization code, which will be used to generate a refresh token.
-
Copy the URL below and substitute your values for the Consumer Key and the Callback URL:
Copyhttps://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=<Consumer Key>&redirect_uri=<Callback URL>
-
Paste the modified URL into your browser and navigate to the page, then authenticate as needed.
Select Allow to authorize access.
After authorizing, the browser redirects you to the Callback URL you configured in the New Connected App. Note the authorization code appended to it.
For example:
https://login.salesforce.com/?code=<authorization code>
Important
You may need to URL-decode the authorization code before using it in the next step.
-
-
Generate a refresh token using the authorization code in POSTMAN.
-
method – POST
-
URL –
https://login.salesforce.com/services/oauth2/token
-
Body – Add the following:
Copygrant_type=authorization_code
client_id=<Consumer Key>
client_secret=<Consumer Secret>
code=<New Authorization Code>
redirect_uri=<Callback URL>You will receive the refresh token in the response this request returns.
-
-
(Optional) To test the refresh token, you can generate an access token.
Create an API request to generate an access token using the refresh token as follows:
CopyPOST /services/oauth2/token HTTP/1.1
Host: login.salesforce.com
client_id=<Consumer Key>
client_secret=<Consumer Secret>
grant_type=refresh_token
refresh_token=<New Refresh Token>