Generating a Refresh Token

Perform the following steps in Salesforce to generate the refresh token:

  1. 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 and client_secret entries respectively.

    • Enter https://login.salesforce.com/ as the Callback URL. This will be used later in this process.

  2. Generate an authorization code, which will be used to generate a refresh token.

    1. Copy the URL below and substitute your values for the Consumer Key and the Callback URL:

      Copy
      https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=<Consumer Key>&redirect_uri=<Callback URL>
    2. 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.

  3. Generate a refresh token using the authorization code in POSTMAN.

    • method – POST

    • URLhttps://login.salesforce.com/services/oauth2/token

    • Body – Add the following:

      Copy
      grant_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.

  4. (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:

    Copy
    POST /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>