Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class Core {
this.apiVersion = config.apiVersion;
this.accessKeyId = config.accessKeyId;
this.accessKeySecret = accessKeySecret;
this.securityToken = config.securityToken;
this.verbose = verbose === true;
// 非 codes 里的值,将抛出异常
this.codes = new Set([200, '200', 'OK', 'Success']);
Expand Down Expand Up @@ -199,7 +200,7 @@ class Core {
}

_buildParams() {
return {
var defaultParams = {
Format: 'JSON',
SignatureMethod: 'HMAC-SHA1',
SignatureNonce: kitx.makeNonce(),
Expand All @@ -208,6 +209,10 @@ class Core {
AccessKeyId: this.accessKeyId,
Version: this.apiVersion,
};
if (this.securityToken) {
defaultParams.SecurityToken = this.securityToken
}
return defaultParams;
}
}

Expand Down
8 changes: 7 additions & 1 deletion lib/roa.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ROAClient {
this.apiVersion = config.apiVersion;
this.accessKeyId = config.accessKeyId;
this.accessKeySecret = config.accessKeySecret;
this.securityToken = config.securityToken;
this.host = url.parse(this.endpoint).hostname;
this.opts = config.opts;
var httpModule = this.endpoint.startsWith('https://') ? require('https') : require('http');
Expand All @@ -70,7 +71,7 @@ class ROAClient {

buildHeaders() {
const now = new Date();
return {
var defaultHeaders = {
accept: 'application/json',
date: now.toGMTString(),
host: this.host,
Expand All @@ -80,6 +81,11 @@ class ROAClient {
'x-acs-version': this.apiVersion,
'x-sdk-client': `Node.js(${process.version}), ${pkg.name}: ${pkg.version}`
};
if (this.securityToken) {
defaultHeaders['x-acs-accesskey-id'] = this.accessKeyId;
defaultHeaders['x-acs-security-token'] = this.securityToken;
}
return defaultHeaders;
}

getCanonicalizedHeaders(headers) {
Expand Down