Skip to content

Token Management Client for Java

Introduction

The Token Management Java client is used to retrieve tokens, which allow applications to access IoT data on customer tenants to whom the application has been provided.

Refer to Token Management Service for more information about the service.

Info

The Token Management Service is currently only available in region Europe 1.

Hint

Placeholders in the following samples are indicated by angular brackets < >.

Token Management Operations

Client Name: TokenManagerClient

Token Expiry

Tokens are valid for 30 minutes. Cache and reuse tokens until their expiry.

Get a Token using Environment Variables

This operation fetches all parameters from the following environment variables:

Environment Variable Description
MDSP_OS_VM_APP_NAME The application name as stored by the version management of the Operator Services (OS_VM).
MDSP_OS_VM_APP_VERSION The application version as stored by the version management of the Operator Services (OS_VM).
MDSP_KEY_STORE_CLIENT_ID The client ID, which is part of the service credentials.
MDSP_KEY_STORE_CLIENT_SECRET The client secret, which is part of the service credentials.

Note

On developer tenants the environment variables must be set manually in the Developer Cockpit. On operator tenants they are set automatically during application registration.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// Construct the TokenManagerClient object
TokenManagerClient token_manager_client = TokenManagerClient.builder()
                    .mindsphereCredentials(<credentials>)
                    .restClientConfig(<config>)
                    .build();

AccessTokenResponse access_token_response = null;

try {
  access_token_response = token_manager_client.getToken();
} catch (MindsphereException e) {
  // Exception handling
}

Get a Token using Service Credentials

Get a token providing the client ID and client secret in the request. The application name and version are automatically fetched from environment variables.

1
2
3
4
5
6
7
8
// Construct the TokenManagerClient object as shown above
AccessTokenResponse access_token_response = null;

try {
  access_token_response = token_manager_client.getToken(<client_id>,<client_secret>);
} catch (MindsphereException e) {
  // Exception handling
}

Get a Token without using Environment Variables

Get a token providing the application name and version, the client ID and the client secret in the request.

1
2
3
4
5
6
7
8
// Construct the TokenManagerClient object as shown above
AccessTokenResponse access_token_response = null;

try {
  access_token_response = token_manager_client.getToken(<application_name>,<application_version>,<client_id>,<client_secret>);
} catch (MindsphereException e) {
  // Exception handling
}

Any questions left?

Ask the community


Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.