Tutorial 2: Refresh Token Management Automation

Uses timestamps and a json file to automatically manage refresh token expiration.

Prerequisites

You will learn

How to manage refresh token expiration using timestamps and a json file.

Regenerate Your Company Request Token

  1. Go to the Company Request Token screen.
  2. Enter your App ID in the required field and click Submit to regenerate your company request token.
  3. Copy/paste the Company UUID and company request token fields to a text file. Confirmation screen showing the Company UUID and company request token successfully created.
  4. Click OK after you have saved this information to a text file.

Setup the NodeJs App

  1. Get the NodeJs sample code.
  2. Open SampleCode/Tutorial_2/RefreshTokenManagement.js in your IDE or text editor.

Regenerate Your Credentials File

  1. Type node RefreshTokenManagement.js in terminal to run the app to generate your credentials.json file. This generates messages in the terminal that show the credentials object. Terminal showing the node RefreshTokenManagement.js command. Credentials object messages.
  2. Fill in the empty fields in this file with the information in the credential object. You can use all of the information from your credentials.json file in the previous concur-get-refresh-token tutorial except for the company request token. Empty fields that need to be populated with credentials.

Regenerate and Store Your Refresh Token in a JSON File

  1. Run the app again. Since the app does not have a stored valid refresh token, the app will not find a valid refresh token in refreshTokenObjectFile.json. Terminal showing node RefreshTokenManagement.js. Response showing no valid refresh token.
  2. The app will call the Oauth2 /token endpoint using your credentials and regenerate your refresh token. Response showing refresh token, private information grayed out.
  3. If the API call is successful, the refresh token data is converted from JSON format into a refresh token object and stored in the file refreshTokenObjectFile.json. Refresh token received and written to file. RefreshTokenObjectFile.json added.

Load Your Stored Refresh Token from a JSON File

  1. Run the app again. Since the app now has a valid refresh token, the app will successfully load and check the validity of the file refreshTokenObjectFile.json. Terminal showing node RefreshTokenManagement.js.
  2. Check for a successful validity check on the refresh token object loaded from refreshTokenObjectFile.json. If the refresh token object validity check is successful, the refresh token object will be stored in the app for use with future API calls. Message that refresh token is valid, and will be used to make API calls.

On this page