Package Exports
- @alicloud/credentials
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@alicloud/credentials) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
English | 简体中文
Alibaba Cloud Credentials for Nodejs
Installation
npm install @alicloud/credentialsNode.js >= 8.5.0 required.
Quick Examples
Before you begin, you need to sign up for an Alibaba Cloud account and retrieve your Credentials.
Credential Type
access_key
Setup access_key credential through [User Information Management][ak], it have full authority over the account, please keep it safe. Sometimes for security reasons, you cannot hand over a primary account AccessKey with full access to the developer of a project. You may create a sub-account [RAM Sub-account][ram] , grant its [authorization][permissions],and use the AccessKey of RAM Sub-account.
const Credentials = require('@alicloud/credentials');
const config = {
type: 'access_key', // credential type
accessKeyId: 'accessKeyId', // AccessKeyId of your account
accessKeySecret: 'accessKeySecret', // AccessKeySecret of your account
}
const cred = new Credentials(config);
let accessKeyId = await cred.getAccessKeyId();
let accessKeySecret = await cred.getAccessKeySecret();
let type = cred.getType();
sts
Create a temporary security credential by applying Temporary Security Credentials (TSC) through the Security Token Service (STS).
const Credentials = require('@alicloud/credentials');
const config = {
type: 'sts', // credential type
accessKeyId: 'accessKeyId', // AccessKeyId of your account
accessKeySecret: 'accessKeySecret', // AccessKeySecret of your account
securityToken: 'securityToken', // Temporary Security Token
}
const cred = new Credentials(config);
let accessKeyId = await cred.getAccessKeyId();
let accessKeySecret = await cred.getAccessKeySecret();
let type = cred.getType();ram_role_arn
By specifying [RAM Role][RAM Role], the credential will be able to automatically request maintenance of STS Token. If you want to limit the permissions([How to make a policy][policy]) of STS Token, you can assign value for Policy.
const Credentials = require('@alicloud/credentials');
const config = {
type: 'ram_role_arn', // credential type
accessKeyId: 'accessKeyId', // AccessKeyId of your account
accessKeySecret: 'accessKeySecret', // AccessKeySecret of your account
roleArn: 'roleArn', // Format: acs🐏:USER_ID:role/ROLE_NAME
roleSessionName: 'roleSessionName', // Role Session Name
policy: 'policy', // Not required, limit the permissions of STS Token
roleSessionExpiration: 3600, // Not required, limit the Valid time of STS Token
}
const cred = new Credentials(config);
let accessKeyId = await cred.getAccessKeyId();
let accessKeySecret = await cred.getAccessKeySecret();
let securityToken = await cred.getSecurityToken();
let type = cred.getType();ecs_ram_role
By specifying the role name, the credential will be able to automatically request maintenance of STS Token.
const Credentials = require('@alicloud/credentials');
const config = {
type: 'ecs_ram_role', // credential type
roleName: 'roleName', // RoleName of your account
}
const cred = new Credentials(config);
let accessKeyId = await cred.getAccessKeyId();
let accessKeySecret = await cred.getAccessKeySecret();
let securityToken = await cred.getSecurityToken();
let type = cred.getType();rsa_key_pair
By specifying the public key ID and the private key file, the credential will be able to automatically request maintenance of the AccessKey before sending the request. Only Japan station is supported.
const Credentials = require('@alicloud/credentials');
const config = {
type: 'rsa_key_pair', // credential type
privateKeyFile: 'privateKeyFile', // The file path to store the PrivateKey
publicKeyId: 'publicKeyId', // PublicKeyId of your account
}
const cred = new Credentials(config);
let accessKeyId = await cred.getAccessKeyId();
let accessKeySecret = await cred.getAccessKeySecret();
let securityToken = await cred.getSecurityToken();
let type = cred.getType();bearer
If credential is required by the Cloud Call Centre (CCC), please apply for Bearer Token maintenance by yourself.
const Credentials = require('@alicloud/credentials');
const config = {
type: 'bearer', // credential type
bearerToken: 'bearerToken', // BearerToken of your account
}
const cred = new Credentials(config);
let bearerToken = await cred.getBearerToken();
let type = cred.getType();Test & Coverage
- run test
npm run test- run code coverage
npm run cov