Skip to content

Commit

Permalink
closes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
DaneEveritt committed Jan 23, 2016
1 parent be48fbd commit aac4988
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/Http/Middleware/APISecretToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class APISecretToken extends Authorization

protected $permissionAllowed = false;

protected $method = '';

protected $url = '';

public function __construct()
{
//
Expand Down Expand Up @@ -102,17 +106,19 @@ public function authenticate(Request $request, Route $route)
throw new HttpException('There was an error while attempting to check your secret key.');
}

if($this->_generateHMAC($request->fullUrl(), $request->getContent(), $decrypted) !== base64_decode($hashed)) {
$this->method = strtoupper($request->method());
$this->url = urldecode($request->fullUrl());
if($this->_generateHMAC($request->getContent(), $decrypted) !== base64_decode($hashed)) {
throw new BadRequestHttpException('The hashed body was not valid. Potential modification of contents in route.');
}

return true;

}

protected function _generateHMAC($url, $body, $key)
protected function _generateHMAC($body, $key)
{
$data = urldecode($url) . '.' . $body;
$data = $this->method . '.' . $this->url . '.' . $body;
return hash_hmac($this->algo, $data, $key, true);
}

Expand Down

0 comments on commit aac4988

Please sign in to comment.