Skip to content

Create a Token

This chapter aims to provide hands-on examples on how to create a token.

Example request

Use the values described in the Authorization-section to construct the Create Token request:

export CLIENT_ID=<YOUR_CLIENT_ID>
export CLIENT_SECRET=<YOUR_CLIENT_SECRET>

curl https://siemens-bt-015.eu.auth0.com/oauth/token \
  -H 'content-type: application/json' \
  -d "{
            \"client_id\":\"$CLIENT_ID\",
            \"client_secret\":\"$CLIENT_SECRET\",
            \"audience\":\"https://horizon.siemens.com\",
            \"grant_type\":\"client_credentials\"
      }"

Example response

{
  "access_token": "eyJ0eXAiOiUSJ9.eyJpc3MiOiJdGlhbHMifQ.MJpcxLfyOt",
  "token_type": "Bearer",
  "expires_in": 86400
}

The token, or JWT (JSON Web Token), is the value of the access_token-property in the response. Your can now use it by passing it in the Authorization-header of any subsequent API requests. The expires_in-property represents the number of seconds your token is valid, usually the value corresponds to 24 hours. When this time has elapsed you will need to create a new token.

E.g. when using the Operations API to list Devices:

export TOKEN=eyJ0eXAiOiUSJ9.eyJpc3MiOiJdGlhbHMifQ.MJpcxLfyOt
export PARTITION=1bcaafc3-d4d3-43e1-ab64-89d8518d5951

curl -H "Authorization: Bearer $TOKEN" "https://api.bpcloud.siemens.com/operations/partitions/$PARTITION/devices"

Note

Your token is valid for a limited time and your application will need to refresh it at regular intervals.

Warning

Make sure to store your token in a safe place, never share it or store it in source control. Anyone with access to your token can access the system on your behalf.