@@ -19,14 +19,14 @@ var util = {
19
19
20
20
var getAuthorization = function ( options , callback ) {
21
21
22
- // 方法一、后端计算签名(推荐 )
22
+ // 方法一、后端通过获取临时密钥,计算签名给到前端(适用于前端调试 )
23
23
var method = ( options . Method || 'get' ) . toLowerCase ( ) ;
24
24
var key = options . Key || '' ;
25
25
var query = options . Query || { } ;
26
26
var headers = options . Headers || { } ;
27
27
var pathname = key . indexOf ( '/' ) === 0 ? key : '/' + key ;
28
- // var url = 'http://127.0.0.1:3000/auth ';
29
- var url = '../server/auth .php' ;
28
+ // var url = 'http://127.0.0.1:3000/sts ';
29
+ var url = '../server/sts .php' ;
30
30
var xhr = new XMLHttpRequest ( ) ;
31
31
var data = {
32
32
method : method ,
@@ -37,18 +37,25 @@ var getAuthorization = function (options, callback) {
37
37
xhr . open ( 'POST' , url , true ) ;
38
38
xhr . setRequestHeader ( 'content-type' , 'application/json' ) ;
39
39
xhr . onload = function ( e ) {
40
- callback ( e . target . responseText ) ;
40
+ try {
41
+ var AuthData = JSON . parse ( e . target . responseText ) ;
42
+ } catch ( e ) {
43
+ }
44
+ callback ( {
45
+ Authorization : AuthData . authorization ,
46
+ XCosSecurityToken : AuthData . sessionToken ,
47
+ } ) ;
41
48
} ;
42
49
xhr . send ( JSON . stringify ( data ) ) ;
43
50
44
- // // 方法二、后端通过获取临时密钥,计算签名给到前端(适用于前端调试 )
51
+ // // 方法二、后端计算签名(推荐 )
45
52
// var method = (options.Method || 'get').toLowerCase();
46
53
// var key = options.Key || '';
47
54
// var query = options.Query || {};
48
55
// var headers = options.Headers || {};
49
56
// var pathname = key.indexOf('/') === 0 ? key : '/' + key;
50
- // // var url = 'http://127.0.0.1:3000/sts ';
51
- // var url = '../server/sts .php';
57
+ // // var url = 'http://127.0.0.1:3000/auth ';
58
+ // var url = '../server/auth .php';
52
59
// var xhr = new XMLHttpRequest();
53
60
// var data = {
54
61
// method: method,
@@ -59,14 +66,7 @@ var getAuthorization = function (options, callback) {
59
66
// xhr.open('POST', url, true);
60
67
// xhr.setRequestHeader('content-type', 'application/json');
61
68
// xhr.onload = function (e) {
62
- // try {
63
- // var AuthData = JSON.parse(e.target.responseText);
64
- // } catch (e) {
65
- // }
66
- // callback({
67
- // Authorization: AuthData.authorization,
68
- // XCosSecurityToken: AuthData.sessionToken,
69
- // });
69
+ // callback(e.target.responseText);
70
70
// };
71
71
// xhr.send(JSON.stringify(data));
72
72
@@ -81,17 +81,8 @@ var getAuthorization = function (options, callback) {
81
81
82
82
} ;
83
83
84
- var getSTS = function ( params , callback ) {
85
- callback ( {
86
- SecretId : 'xxx' ,
87
- SecretKey : 'xxx' ,
88
- XCosSecurityToken : 'xxx' ,
89
- } ) ;
90
- } ;
91
-
92
84
var cos = new COS ( {
93
85
getAuthorization : getAuthorization ,
94
- // getSTS: getSTS,
95
86
} ) ;
96
87
var TaskId ;
97
88
0 commit comments