Skip to content

Commit fefa494

Browse files
committed
Merge pull request #29 from rwifeng/callback_verify
Callback verify
2 parents c3632bb + 422f896 commit fefa494

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

qiniu/auth_digest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ 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+
$url = parse_url($url);
53+
$data = '';
54+
if (isset($url['path'])) {
55+
$data = $url['path'];
56+
}
57+
if (isset($url['query'])) {
58+
$data .= '?' . $url['query'];
59+
}
60+
$data .= "\n";
61+
62+
$data .= $body;
63+
$token = 'QBox ' . $this->Sign($data);
64+
return $auth === $token;
65+
}
4966
}
5067

5168
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)