Skip to content

Commit

Permalink
更新示例
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Mar 9, 2020
1 parent 60f8793 commit 8516675
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ var cos = new COS({
success: function (result) {
var data = result.data;
var credentials = data && data.credentials;
if (!data || !credentials) return console.error('credentials invalid');
callback({
TmpSecretId: credentials.tmpSecretId,
TmpSecretKey: credentials.tmpSecretKey,
XCosSecurityToken: credentials.sessionToken,
StartTime: data.startTime, // 密钥申请时服务器时间,签名用的开始时间,避免客户端时间偏差导致报错
ExpiredTime: data.expiredTime, // SDK 在 ExpiredTime 时间前,不会再次调用 getAuthorization
StartTime: data.startTime, // 时间戳,单位秒,如:1580000000,建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
ExpiredTime: data.expiredTime, // 时间戳,单位秒,如:1580000900
});
}
});
Expand Down
20 changes: 12 additions & 8 deletions demo/demo-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ var getAuthorization = function(options, callback) {
dataType: 'json',
success: function(result) {
var data = result.data;
var credentials = data.credentials;
var credentials = data && data.credentials;
if (!data || !credentials) return console.error('credentials invalid');
callback({
TmpSecretId: credentials.tmpSecretId,
TmpSecretKey: credentials.tmpSecretKey,
XCosSecurityToken: credentials.sessionToken,
StartTime: data.startTime, // 密钥申请时服务器时间,签名用的开始时间,避免客户端时间偏差导致报错
ExpiredTime: data.expiredTime, // SDK 在 ExpiredTime 时间前,不会再次调用 getAuthorization
StartTime: data.startTime, // 时间戳,单位秒,如:1580000000,建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
ExpiredTime: data.expiredTime, // 时间戳,单位秒,如:1580000900
});
}
});
Expand All @@ -37,13 +38,14 @@ var getAuthorization = function(options, callback) {
// dataType: 'json',
// success: function(result) {
// var data = result.data;
// var credentials = data.credentials;
// var credentials = data && data.credentials;
// if (!data || !credentials) return console.error('credentials invalid');
// callback({
// TmpSecretId: credentials.tmpSecretId,
// TmpSecretKey: credentials.tmpSecretKey,
// XCosSecurityToken: credentials.sessionToken,
// StartTime: data.startTime, // 密钥申请时服务器时间,签名用的开始时间,避免客户端时间偏差导致报错
// ExpiredTime: data.expiredTime,
// StartTime: data.startTime, // 时间戳,单位秒,如:1580000000,建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
// ExpiredTime: data.expiredTime, // 时间戳,单位秒,如:1580000900
// ScopeLimit: true, // 细粒度控制权限需要设为 true,会限制密钥只在相同请求时重复使用
// });
// }
Expand All @@ -64,9 +66,11 @@ var getAuthorization = function(options, callback) {
// },
// dataType: 'json',
// success: function(result) {
// var data = result.data;
// if (!data || !data.authorization) return console.error('authorization invalid');
// callback({
// Authorization: result.data,
// // XCosSecurityToken: sessionToken, // 如果使用临时密钥,需要传 sessionToken
// Authorization: data.authorization,
// // XCosSecurityToken: data.sessionToken, // 如果使用临时密钥,需要传 sessionToken
// });
// }
// });
Expand Down

0 comments on commit 8516675

Please sign in to comment.