Skip to content

Commit e1d1e35

Browse files
committed
callback verify
1 parent 0ab32bf commit e1d1e35

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

qiniu/auth_digest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ public function SignRequest($req, $incbody) // => ($token, $error)
4646
}
4747
return $this->Sign($data);
4848
}
49+
50+
public function VerifyCallback($auth, $url, $body) // ==> bool
51+
{
52+
53+
$url = parse_url($url);
54+
55+
$data = '';
56+
if (isset($url['path'])) {
57+
$data = $url['path'];
58+
}
59+
if (isset($url['query'])) {
60+
$data .= '?' . $url['query'];
61+
}
62+
$data .= "\n";
63+
64+
$data .= $body;
65+
$token = 'QBox ' . $this->Sign($data);
66+
return $auth === $token;
67+
}
4968
}
5069

5170
function Qiniu_SetKeys($accessKey, $secretKey)

tests/AuthDigestTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
class AuthDigestTest extends PHPUnit_Framework_TestCase
66
{
7+
78
public function testEncode()
89
{
910
$cases = array(
@@ -16,6 +17,17 @@ public function testEncode()
1617
}
1718
}
1819

20+
public function testVerifyCallback()
21+
{
22+
initKeys();
23+
$mac1 = Qiniu_RequireMac(null);
24+
$auth = 'QBox Vhiv6a22kVN_zhtetbPNeG9sY3JUL1HG597EmBwQ:JrRyg9So6DNrNDY5qj1sygt0SmQ=';
25+
$url = 'http://rs.qbox.me/batch';
26+
$body = 'op=/delete/cGhwc2RrOnRlc3RPcDI=&op=/delete/cGhwc2RrOnRlc3RPcDM=&op=/delete/cGhwc2RrOnRlc3RPcDQ=';
27+
$pass = $mac1->VerifyCallback($auth, $url, $body);
28+
$this->assertTrue($pass);
29+
}
30+
1931
/* public function testSetKeys()
2032
{
2133
$mac1 = Qiniu_RequireMac(null);

0 commit comments

Comments
 (0)