Skip to main content
Anthony_E
Staff
Staff
November 4, 2024

Technical Tip: Saving an Access Token as an Environment Variable for use in scripts

  • November 4, 2024
  • 0 replies
  • 91 views
Description This article describes how to save an Access Token as an Environment Variable for use in scripts.
Scope FortiDLP.
Solution

An access Token must be included to authenticate API requests to the Reveal infrastructure. it is recommended to save access tokens as environment variables, so it is not exposed in scripts or terminal sessions.

 

Generating an Access Token:

  1. Navigate to the Admin section in the Reveal UI.
  2. Select Access Tokens.
  3. In the Name field, type a name to identify the token.
  4. In the Role menu, do one of the following:
    • To grant the token access to all API endpoints, select *.
    • To grant the token access determined by a custom role, select the appropriate role.
  5. Select Create.
  6. A button to copy the token should appear, as shown in the screenshot below.


Anthony_E_0-1730722470115.jpeg

 

Saving the Token as an Environment Variable via PowerShell:

The command below can be used, replacing <variable-name> with the name chosen, and <access-token> replaced by the Token generated on the web UI:

 

$Env:<variable-name> = "<access-token>"

 

Saving a Token as an Environment Variable via GUI:

  1. In the Windows search bar, type in 'Edit the system environment variables'.
  2. Select the entry matching 'Edit the system environment variables'.
  3. Select 'Environment variables...'.

 

Picture5.png

 

  1. Select 'New...'. under User variables.

 

Picture6.png

 

  1. Enter a variable name, and paste the Token code (obtained from the web UI in the previous section) into the 'Variable value' field.

Picture7.png

 

  1. Select 'OK'.
  2. An access Token is now saved as an environment variable.

 

Accessing the Environment Variable in PowerShell.

The environment variable can now accessed in PowerShell using this syntax:

 

$Env:EXAMPLE_ACCESS_TOKEN

 

Response:

 

eyJxxxxx.v1.xxxxx

 

Related document:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.2