Skip to content

Commit 98f532c

Browse files
committed
[update] nodejs支持临时密钥
1 parent 1f0c5b4 commit 98f532c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Qcloud_CDN_API/nodejs/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,36 @@ var METHOD = 'POST';
1414
var QcloudSDK = function() {
1515
this.secretKey = '';
1616
this.secretId = '';
17+
this.token = '';
1718
}
1819

1920
QcloudSDK.prototype.config = function(userConfig) {
2021
checkUserConfig(userConfig)
2122

2223
this.secretKey = userConfig.secretKey;
2324
this.secretId = userConfig.secretId;
25+
this.token = userConfig.token;
2426
}
2527

2628
QcloudSDK.prototype.request = function(actionName, params, callback) {
2729
checkUserConfig({
2830
secretKey: this.secretKey,
29-
secretId: this.secretId
31+
secretId: this.secretId,
32+
token: this.token,
3033
})
3134

3235
params = params || {};
3336
var timestamp = Math.ceil((new Date()-0)/1000);
3437
var nonce = _.random(1000000);
35-
var signature = createSignature(actionName, nonce, timestamp, params, this.secretKey, this.secretId);
38+
var signature = createSignature(actionName, nonce, timestamp, params, this.secretKey, this.secretId, this.token);
3639

3740
var requestData = _.assign({
3841
'Action': actionName,
3942
'Timestamp': timestamp,
4043
'Nonce': nonce,
4144
'SecretId': this.secretId,
4245
'Signature': signature,
46+
'Token': this.token
4347
}, params)
4448

4549
requestData = commonUtils.serialize(requestData)
@@ -67,12 +71,13 @@ function checkUserConfig(userConfig) {
6771
}
6872
}
6973

70-
function createSignature(actionName, nonce, timestamp, params, secretKey, secretId) {
74+
function createSignature(actionName, nonce, timestamp, params, secretKey, secretId, token) {
7175
var originObject = _.assign({
7276
'Action': actionName,
7377
'Nonce': nonce,
7478
'SecretId': secretId,
75-
'Timestamp': timestamp
79+
'Timestamp': timestamp,
80+
'Token': token
7681
}, params);
7782
var sortedObject = commonUtils.sortObject(originObject);
7883
var serializeString = commonUtils.serialize(sortedObject);

0 commit comments

Comments
 (0)