Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Added late static binding for request parameters #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions classes/Kohana/RestUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ protected function _auth()
if (self::AUTH_TYPE_HASH == $this->_auth_type)
{
// We add the "Basic " prefix here, so that the GET parameter doesn't need to provide it.
$this->_auth_hash($this->_get_auth_param(self::AUTH_KEY_HASH));
$this->_auth_hash($this->_get_auth_param(static::AUTH_KEY_HASH));
}
else
{
$this->_api_key = $this->_get_auth_param(self::AUTH_KEY_API);
$this->_api_key = $this->_get_auth_param(static::AUTH_KEY_API);
$this->_load();
if (self::AUTH_TYPE_SECRET == $this->_auth_type && $this->_secret_key != $this->_get_auth_param(self::AUTH_KEY_SECRET))
if (self::AUTH_TYPE_SECRET == $this->_auth_type && $this->_secret_key != $this->_get_auth_param(static::AUTH_KEY_SECRET))
{
throw $this->_altered_401_exception('Invalid API or secret key');
}
Expand All @@ -106,7 +106,7 @@ protected function _auth_hash($hash)
$split = array_filter(explode(':', base64_decode($hash)));
if (count($split) != 3)
{
throw $this->_altered_401_exception('Invalid '. self::AUTH_KEY_HASH .' value');
throw $this->_altered_401_exception('Invalid '. static::AUTH_KEY_HASH .' value');
}

$this->_api_key = $split[0];
Expand All @@ -116,14 +116,14 @@ protected function _auth_hash($hash)

// Validate timestamp.
if (time() > ($timestamp + (60 * self::MAX_AUTH_TIME))) {
throw $this->_altered_401_exception('Invalid '. self::AUTH_KEY_HASH .' value');
throw $this->_altered_401_exception('Invalid '. static::AUTH_KEY_HASH .' value');
}

// We load the user now, so that we can validate the hashed timestamp with the secret key.
$this->_load();

if (!$this->_secret_key || $secret_hash !== md5($timestamp . $this->_secret_key)) {
throw $this->_altered_401_exception('Invalid '. self::AUTH_KEY_HASH .' value');
throw $this->_altered_401_exception('Invalid '. static::AUTH_KEY_HASH .' value');
}
}

Expand Down