forked from hitbtc-com/hitbtc-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hitbtc-com#1 from toooni/master
guzzle 6
- Loading branch information
Showing
5 changed files
with
79 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Hitbtc; | ||
|
||
|
||
use Psr\Http\Message\RequestInterface; | ||
|
||
class AuthMiddleware | ||
{ | ||
protected $publicKey; | ||
protected $secretKey; | ||
|
||
public function __construct($publicKey, $secretKey) | ||
{ | ||
$this->publicKey = $publicKey; | ||
$this->secretKey = $secretKey; | ||
} | ||
|
||
/** | ||
* @param callable $handler | ||
* | ||
* @return callable | ||
*/ | ||
public function __invoke(callable $handler) | ||
{ | ||
return function (RequestInterface $request, array $options) use (&$handler) { | ||
$queryString = $request->getUri()->getQuery(); | ||
$queryParts = \GuzzleHttp\Psr7\parse_query($queryString); | ||
|
||
$queryParts['apikey'] = $this->publicKey; | ||
$queryParts['nonce'] = $this->getNonce(); | ||
|
||
$queryString = \GuzzleHttp\Psr7\build_query($queryParts); | ||
$request = $request->withUri($request->getUri()->withQuery($queryString)); | ||
|
||
$message = $request->getUri()->getPath(). '?' . $queryString . $request->getBody(); | ||
$sign = strtolower(hash_hmac('sha512', $message, $this->secretKey)); | ||
|
||
$request = $request | ||
->withAddedHeader('Api-Signature', $sign) | ||
->withAddedHeader('User-Agent', 'Hitbtc PHP Client') | ||
; | ||
|
||
return $handler($request, $options); | ||
}; | ||
} | ||
|
||
protected function getNonce() | ||
{ | ||
return intval(microtime(true) * 1000); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters