MindSphere Credntials¶
简介¶
MindSphere Credentials 包含获取新令牌和储存获取的令牌的细节。
提示
下面示例中的占位符用尖括号 < >
表示。
创建 MindsphereCredentials 对象¶
对象名称: MindsphereCredentials
使用用户令牌创建 MindsphereCredentials¶
应用可以使用UserCredentials
对象,传递由请求头部获得的用户令牌到客户端。如下所示:
// Require the class UserCredentials available in mindsphere-sdk-node-core module
const UserCredentials = require('mindsphere-sdk-node-core').UserCredentials;
// Construct the UserCredentials object
let user_credentials = new UserCredentials({'authorization': '<user_token>'});
使用 App Specific Service Credentials 创建 MindsphereCredentials¶
App Specific Service Credentials 必须由编程方式或者通过环境变量提供。 App Specific Service Credentials 通过 Developer Cockpit 或者 Operator Cockpit 获得。
// Require the class AppCredentials available in `mindsphere-sdk-node-core` module
const AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
// Construct the AppCredentials object
let app_credentials = new AppCredentials({
keyStoreClientId: '<client_id>',
keyStoreClientSecret: '<client_secret>',
appName: '<app-name>',
appVersion: '<app_version>',
hostTenant: '<host_tenant>',
userTenant: '<user_tenant>'
});
使用 Tenant Specific Service Credentials 创建 MindsphereCredentials¶
Tenant Specific Service Credentials 必须由编程方式或者通过环境变量提供。 Tenant Specific Service Credentials 按照使用 Service Credentials 访问 MindSphere APIs 中描述的方式获得。如果凭证通过环境变量设置,TenantCredentials
对象不必构建。
// Require the class TenantCredentials available in mindsphere-sdk-node-core module
const TenantCredentials = require('mindsphere-sdk-node-core').TenantCredentials;
// Construct the TenantCredentials object
let tenant_credentials = new TenantCredentials({
clientId: '<client_id>',
clientSecret: '<client_secret>',
tenant:'<tenant_id>'
});
使用子租户扮演的 Tenant specific Service Credentials 创建 MindsphereCredentials¶
子租户扮演的 Tenant Specific Service Credentials 必须由编程方式或者通过环境变量提供。如果凭证通过环境变量设置,TenantCredentials
对象不必构建。
// Require the class TenantCredentials available in mindsphere-sdk-node-core module
const TenantCredentials = require('mindsphere-sdk-node-core').TenantCredentials;
// Construct the TenantCredentials object
let tenant_credentials = new TenantCredentials({
clientId: '<client_id>',
clientSecret: '<client_secret>',
tenant:'<tenant_id>',
subTenant:'<subtenant_id>'
});
Last update: March 22, 2023