Skip to content

MindSphere 凭证

简介

MindSphere 凭证包含获取新令牌和存储已获取令牌的详细说明。

提示

以下示例中的占位符由尖括号 < > 表示。

创建 MindsphereCredentials 对象

对象名称: MindsphereCredentials

使用用户令牌创建 MindsphereCredentials

MindsphereCredentials credentials = MindsphereCredentials.userTokenBuilder()
                                        .authorization(<user_token>)
                                        .build();
弃用方法

以下使用用户令牌创建服务凭证的方法已被弃用并且不应该再被使用:

MindsphereCredentials credentials = MindsphereCredentials.builder()
                                        .authorization(<user_token>)
                                        .build();

使用应用特定服务凭证创建 MindsphereCredentials

应用特定服务凭证从 Developer CockpitOperator Cockpit 中获取。在应用开发期间,您也需要会以编程方式提供服务凭证。最终的应用应该从环境变量中获取客户端 ID、客户端密钥、应用名称和应用版本,并从用户令牌中获取主租户和用户租户如上所示。

```java tab="Provide service credentials programmatically" MindsphereCredentials credentials = MindsphereCredentials.appCredentialsBuilder() .keyStoreClientId() .keyStoreClientSecret() .appName() .appVersion() .hostTenant() .userTenant() .build();

```java tab="Use environment variables and user token"
MindsphereCredentials credentials = MindsphereCredentials.appCredentialsBuilder()
                                        .authorization(<user_token>)
                                        .build();

说明

主租户和用户租户值不应该在应用中进行硬编码,因为它们可能会发生更改。MindSphereCredentials 对象可以从作为 authorization 参数提供的用户令牌中提取这些值。

使用租户特定服务凭证创建 MindsphereCredentials

租户特定服务凭证必须通过编程方式或通过环境变量提供。租户特定服务凭证如用服务凭证访问 Mindsphere APIs中描述的一样获得。如果凭证通过环境变量设置,MindsphereCredentials 对象不必被构建。

MindsphereCredentials credentials = MindsphereCredentials.tenantCredentialsBuilder()
                                        .clientId(<client_id>)
                                        .clientSecret(<client_secret>)
                                        .tenant(<tenant>)
                                        .build();
弃用方法

以下创建租户特定服务凭证的方法已被弃用并且不应被再使用:

MindsphereCredentials credentials = MindsphereCredentials.builder()
                                        .clientId(<client_id>)
                                        .clientSecret(<client_secret>)
                                        .tenant(<tenant_name>)
                                        .build();

使用为子租户扮演的租户特定服务凭证为创建 MindsphereCredentials

为子租户扮演的租户特定服务凭证必须通过编程方式或通过环境变量

MindsphereCredentials credentials = MindsphereCredentials.tenantCredentialsBuilder()
                                        .clientId(<client_id>)
                                        .clientSecret(<client_secret>)
                                        .tenant(<tenant>)
                                        .subTenant(<subtenant>)
                                        .tokenType(TokenScope.SUB_TENANT)
                                        .build();

还有问题?

向社区提问


除非另行声明,该网站内容遵循MindSphere开发许可协议.


Last update: July 11, 2019