New:Socket for Asana Is Now Available.Learn more
Get Started

@alicloud/credentials

Package Overview
Dependencies
Maintainers
14
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alicloud/credentials

alibaba cloud node.js sdk credentials

Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
61K
-43.02%
Maintainers
14
Weekly downloads
 
Created
Source

English | 简体中文

Alibaba Cloud Credentials for Nodejs

npm version Travis Build Status Appveyor Build status codecov license

Installation

npm install @alicloud/credentials

Node.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:ram::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` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests.
}
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

License

MIT

Copyright (c) 2009-present, Alibaba Cloud All rights reserved.

Keywords

alibaba cloud

FAQs

Package last updated on 04 Feb 2020

Related posts