Cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot get token using Java SDK v2.1.0 "Unable to retrieve Technical token successfully."

Experimenter
Experimenter

Hello,

 

I am trying to use the Mindsphere Java SDK (v2.1.0) and just trying to connect to the platform.

 

I first created an app by following the steps at https://developer.mindsphere.io/howto/howto-cf-running-app.html.

My app is just a simple python web server that serves static pages.

 

Then I continued with the following steps kindly explained by Siemens support, in order to create client credentials.

1) Go to Developer Cockpit you can see three tabs left top.
2) Select Authorization Management Tab.
3) Select App Credentials from left.
4) Select particular app to generate technical credential.
5) Click on issue access.
6) Note down the client id and client Secret.
7) Now you can use TokenManager API to generate the token using this above generated credentials.

I believed my client credentials are linked to my particular app, since I generated them from it. Note that this app is not bind to any service whatsoever, it's just a simple web server.

 

And finally the code that I am using to try and connect to the Mindsphere platform (I replaced the values between <…> with my real values of course).

This code is running on my desktop PC as this is the setup I want to use for the development and testing phase.

 

public static void main(String[] args) {

    RestClientConfig config = RestClientConfig.builder()
            .build();

    MindsphereCredentials credentials = MindsphereCredentials.builder()
            .clientId("<CLIENT ID>")
            .clientSecret("<CLIENT SECRET>")
            .tenant("<TENANT>")
            .build();

    AgentsClient agentsClient = AgentsClient.builder()
            .mindsphereCredentials(credentials)
            .restClientConfig(config)
            .build();

    AgentsList agentsList = null;
    try {
        agentsList = agentsClient.getAllAgents(null, 100, 0, null);
    } catch (MindsphereException e) {
        System.out.println("error: " + e.getErrorMessage());
    }

}

 

I am getting an exception with the following error: “Unable to retrieve Technical token successfully.”

I am following the guide at https://developer.mindsphere.io/resources/mindsphere-sdk-java/sdkreadme.html.

 

Is there anything I am missing? Anything wrong with the code?

Should I grant additional access rights?

 

Thanks in advance!

Nicolas

1 REPLY

Re: Cannot get token using Java SDK v2.1.0 "Unable to retrieve Technical token successfully.&qu

Creator
Creator

hello @nteolane 

 

Unfortunateky SDK 2.1.0 currently does not support the use of App (Technical) credentails  to make MindSphere calls.

 

MindsphereCredentials credentials = MindsphereCredentials.builder()
            .clientId("<CLIENT ID>")
            .clientSecret("<CLIENT SECRET>")
            .tenant("<TENANT>")
            .build();

Here Client id & Client secret are Developer Service Credentials (not Token Manager Service Credentials).

 

You can use the tokenmanager-sdk release as part of SDK 2.1.1 to fetch the token and set it as usertoken.

 

MindsphereCredentials userTokencreds = MindsphereCredentials.builder()
                                        .authorization("< usertokenFromRequestHeader >")
                                        .build();

TokenManagerClient tokenManagerClient = TokenManagerClient.builder()
					  .mindsphereCredentials(userTokencreds)
					  .restClientConfig(config)
					  .build();
										
AccessTokenResponse accessTokenResponse = tokenManagerClient.getToken();

MindsphereCredentials techTokenCreds = MindsphereCredentials.builder()
                                        .authorization(accessTokenResponse.getAccessToken())
                                        .build();

Now you can use the `techTokenCreds ` object in your client to make MindSphere API calls.

 

 

However we will be adding support for App (Technical) credentials in the next version SDK 2.2 and will be available very soon.

 

Regards

Pruthula