@@ -77,7 +77,8 @@ public function uploadToken(
77
77
$ expires = 3600 ,
78
78
$ policy = null ,
79
79
$ strictPolicy = true
80
- ) {
80
+ )
81
+ {
81
82
$ deadline = time () + $ expires ;
82
83
$ scope = $ bucket ;
83
84
if ($ key !== null ) {
@@ -142,4 +143,51 @@ public function authorization($url, $body = null, $contentType = null)
142
143
$ authorization = 'QBox ' . $ this ->signRequest ($ url , $ body , $ contentType );
143
144
return array ('Authorization ' => $ authorization );
144
145
}
146
+
147
+ public function authorizationV2 ($ url , $ method , $ body = null , $ contentType = null )
148
+ {
149
+ $ urlItems = parse_url ($ url );
150
+ $ host = $ urlItems ['host ' ];
151
+
152
+ if (isset ($ urlItems ['port ' ])) {
153
+ $ port = $ urlItems ['port ' ];
154
+ } else {
155
+ $ port = '' ;
156
+ }
157
+
158
+ $ path = $ urlItems ['path ' ];
159
+ if (isset ($ urlItems ['query ' ])) {
160
+ $ query = $ urlItems ['query ' ];
161
+ } else {
162
+ $ query = '' ;
163
+ }
164
+
165
+ //write request uri
166
+ $ toSignStr = $ method . ' ' . $ path ;
167
+ if (!empty ($ query )) {
168
+ $ toSignStr .= '? ' . $ query ;
169
+ }
170
+
171
+ //write host and port
172
+ $ toSignStr .= "\nHost: " . $ host ;
173
+ if (!empty ($ port )) {
174
+ $ toSignStr .= ": " . $ port ;
175
+ }
176
+
177
+ //write content type
178
+ if (!empty ($ contentType )) {
179
+ $ toSignStr .= "\nContent-Type: " . $ contentType ;
180
+ }
181
+
182
+ $ toSignStr .= "\n\n" ;
183
+
184
+ //write body
185
+ if (!empty ($ body )) {
186
+ $ toSignStr .= $ body ;
187
+ }
188
+
189
+ $ sign = $ this ->sign ($ toSignStr );
190
+ $ auth = 'Qiniu ' . $ sign ;
191
+ return array ('Authorization ' => $ auth );
192
+ }
145
193
}
0 commit comments