Skip to content

Commit

Permalink
Merge pull request #117 from longbai/7.0
Browse files Browse the repository at this point in the history
rename function
  • Loading branch information
longbai committed Mar 1, 2015
2 parents f67af3f + ceea222 commit 53bfd3a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/Qiniu/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ public function __construct($accessKey, $secretKey)
$this->secretKey = $secretKey;
}

public function token($data)
public function sign($data)
{
$hmac = hash_hmac('sha1', $data, $this->secretKey, true);
return $this->accessKey . ':' . \Qiniu\base64_urlSafeEncode($hmac);
}

public function tokenWithData($data)
public function signWithData($data)
{
$data = \Qiniu\base64_urlSafeEncode($data);
return $this->token($data) . ':' . $data;
return $this->sign($data) . ':' . $data;
}

public function tokenOfRequest($urlString, $body, $contentType = null)
public function signRequest($urlString, $body, $contentType = null)
{
$url = parse_url($urlString);
$data = '';
Expand All @@ -42,12 +42,12 @@ public function tokenOfRequest($urlString, $body, $contentType = null)
($contentType == 'application/x-www-form-urlencoded') || $contentType == 'application/json') {
$data .= $body;
}
return $this->token($data);
return $this->sign($data);
}

public function verifyCallback($contentType, $originAuthorization, $url, $body)
{
$authorization = 'QBox ' . $this->tokenOfRequest($url, $body, $contentType);
$authorization = 'QBox ' . $this->signRequest($url, $body, $contentType);
return $originAuthorization === $authorization;
}

Expand All @@ -63,7 +63,7 @@ public function privateDownloadUrl($baseUrl, $expires = 3600)
}
$baseUrl .= $deadline;

$token = $this->token($baseUrl);
$token = $this->sign($baseUrl);
return "$baseUrl&token=$token";
}

Expand All @@ -84,7 +84,7 @@ public function uploadToken(
$args['scope'] = $scope;
$args['deadline'] = $deadline;
$b = json_encode($args);
return $this->tokenWithData($b);
return $this->signWithData($b);
}

private static $policyFields = array(
Expand Down Expand Up @@ -132,7 +132,7 @@ private static function copyPolicy($policy, $originPolicy, $strictPolicy)

public function authorization($url, $body = null, $contentType = null)
{
$authorization = 'QBox ' . $this->tokenOfRequest($url, $body, $contentType);
$authorization = 'QBox ' . $this->signRequest($url, $body, $contentType);
return array('Authorization' => $authorization);
}
}
14 changes: 7 additions & 7 deletions tests/Qiniu/Tests/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ function time()
class AuthTest extends \PHPUnit_Framework_TestCase
{

public function testToken()
public function testSign()
{
global $dummyAuth;
$token = $dummyAuth->token('test');
$token = $dummyAuth->sign('test');
$this->assertEquals('abcdefghklmnopq:mSNBTR7uS2crJsyFr2Amwv1LaYg=', $token);
}

public function testTokenWithData()
public function testSignWithData()
{
global $dummyAuth;
$token = $dummyAuth->tokenWithData('test');
$token = $dummyAuth->signWithData('test');
$this->assertEquals('abcdefghklmnopq:-jP8eEV9v48MkYiBGs81aDxl60E=:dGVzdA==', $token);
}

public function testTokenOfRequest()
public function testSignRequest()
{
global $dummyAuth;
$token = $dummyAuth->tokenOfRequest('http://www.qiniu.com?go=1', 'test', '');
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', '');
$this->assertEquals('abcdefghklmnopq:cFyRVoWrE3IugPIMP5YJFTO-O-Y=', $token);
$ctype = 'application/x-www-form-urlencoded';
$token = $dummyAuth->tokenOfRequest('http://www.qiniu.com?go=1', 'test', $ctype);
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', $ctype);
$this->assertEquals($token, 'abcdefghklmnopq:svWRNcacOE-YMsc70nuIYdaa1e4=');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Qiniu/Tests/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testGet()
public function testGetQiniu()
{
$response = Client::get('up.qiniu.com');
$this->assertEquals($response->statusCode, 405);
$this->assertEquals(405, $response->statusCode);
$this->assertNotNull($response->body);
$this->assertNotNull($response->xReqId());
$this->assertNotNull($response->xLog());
Expand Down

0 comments on commit 53bfd3a

Please sign in to comment.