The chat responses are generated using Generative AI technology for intuitive search and may not be entirely accurate. They are not intended as professional advice. For full details, including our use rights, privacy practices and potential export control restrictions, please refer to our Generative AI Service Terms of Use and Generative AI Service Privacy Information. As this is a test version, please let us know if something irritating comes up. Like you get recommended a chocolate fudge ice cream instead of an energy managing application. If that occurs, please use the feedback button in our contact form!
Skip to content
Insights Hub and Industrial IoT

Insights Hub drives smart manufacturing through the industrial Internet of Things. Gain actionable insights with asset and operational data and improve your processes.

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.

Further implementation of the TokenManager SDK library has been shown in a sample project that you can download and test in local or on Insights Hub application. Please refer to this repository: industrial-iot-java-sdk-examples

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

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 the following parameters from environment variables:

Environment VariableDescription
MDSP_OS_VM_APP_NAMEThe application name as stored by the version management of the Operator Services (OS_VM).
MDSP_OS_VM_APP_VERSIONThe application version as stored by the version management of the Operator Services (OS_VM).
MDSP_KEY_STORE_CLIENT_IDThe client ID, which is part of the service credentials.
MDSP_KEY_STORE_CLIENT_SECRETThe client secret, which is part of the service credentials.

The MDSP_HOST_TENANT and MDSP_USER_TENANT parameters are obtained from the user token passed via a MindsphereCredentials object.

Environment Variables

On developer tenants the environment variables must be set manually in the Cloud Foundry environment using the command cf env or in the manifest.yml. On operator tenants they are set automatically during application registration.

Credentials

Credentials differ between operator and developer tenants and should not be hard-coded in the final application. You are responsible for keeping the credentials safe.

// Construct the MindsphereCredentials object using the user token
MindsphereCredentials credentials = MindsphereCredentials.userTokenBuilder()
                                        .authorization(<user_token>)
                                        .build();

// 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.

// Construct the MindsphereCredentials object and supply the user token as shown above

// 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.

// Construct the MindsphereCredentials object and supply the user token as shown above

// 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
}