Don't base64 decode the bearer token

Signed-off-by: Alex Bilbie <alex@alexbilbie.com>
This commit is contained in:
Alex Bilbie 2012-10-10 09:32:50 +01:00
parent 4fdfb63128
commit 5ed4a8a2c4

View File

@ -54,9 +54,9 @@ class Server
/** /**
* Error codes. * Error codes.
* *
* To provide i8ln errors just overwrite the keys * To provide i8ln errors just overwrite the keys
* *
* @var array * @var array
*/ */
public $errors = array( public $errors = array(
@ -68,7 +68,7 @@ class Server
/** /**
* Constructor * Constructor
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -92,7 +92,7 @@ class Server
if ($this->_type === strtolower(substr($method, 2))) { if ($this->_type === strtolower(substr($method, 2))) {
return $this->_typeId; return $this->_typeId;
} }
return false; return false;
} }
@ -101,7 +101,7 @@ class Server
/** /**
* Register a database abstrator class * Register a database abstrator class
* *
* @access public * @access public
* @param object $db A class that implements OAuth2ServerDatabase * @param object $db A class that implements OAuth2ServerDatabase
* @return void * @return void
@ -110,24 +110,24 @@ class Server
{ {
$this->_db = $db; $this->_db = $db;
} }
/** /**
* Init function * Init function
* *
* @access public * @access public
* @return void * @return void
*/ */
public function init() public function init()
{ {
$accessToken = null; $accessToken = null;
$_SERVER['REQUEST_METHOD'] = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] = isset($_SERVER['REQUEST_METHOD']) ?
$_SERVER['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD'] :
null; null;
// Try and get the access token via an access_token or oauth_token parameter // Try and get the access token via an access_token or oauth_token parameter
switch ($_SERVER['REQUEST_METHOD']) switch ($_SERVER['REQUEST_METHOD'])
{ {
case 'POST': case 'POST':
$accessToken = isset($_POST[$this->_config['token_key']]) ? $accessToken = isset($_POST[$this->_config['token_key']]) ?
$_POST[$this->_config['token_key']] : $_POST[$this->_config['token_key']] :
@ -145,17 +145,17 @@ class Server
if (function_exists('getallheaders')) { if (function_exists('getallheaders')) {
$headers = getallheaders(); $headers = getallheaders();
if (isset($headers['Authorization'])) { if (isset($headers['Authorization'])) {
$rawToken = trim(str_replace('Bearer', '', $headers['Authorization'])); $rawToken = trim(str_replace('Bearer', '', $headers['Authorization']));
if ( ! empty($rawToken)) { if ( ! empty($rawToken)) {
$accessToken = base64_decode($rawToken); $accessToken = $rawToken;
} }
} }
} }
if ($accessToken) { if ($accessToken) {
$result = $this->_dbCall('validateAccessToken', $accessToken); $result = $this->_dbCall('validateAccessToken', $accessToken);
@ -167,7 +167,7 @@ class Server
} else { } else {
if ( ! array_key_exists('id', $result) || if ( ! array_key_exists('id', $result) ||
! array_key_exists('owner_id', $result) || ! array_key_exists('owner_id', $result) ||
! array_key_exists('owner_type', $result)) { ! array_key_exists('owner_type', $result)) {
throw new ServerException($this->errors['missing_access_token_details']); throw new ServerException($this->errors['missing_access_token_details']);
} }
@ -193,12 +193,12 @@ class Server
} }
} }
/** /**
* Test if the access token has a specific scope * Test if the access token has a specific scope
* *
* @param mixed $scopes Scope(s) to check * @param mixed $scopes Scope(s) to check
* *
* @access public * @access public
* @return string|bool * @return string|bool
*/ */
@ -209,7 +209,7 @@ class Server
if (in_array($scopes, $this->_scopes)) { if (in_array($scopes, $this->_scopes)) {
return true; return true;
} }
return false; return false;
} elseif (is_array($scopes)) { } elseif (is_array($scopes)) {
@ -221,16 +221,16 @@ class Server
} }
} }
return true; return true;
} }
return false; return false;
} }
/** /**
* Call database methods from the abstractor * Call database methods from the abstractor
* *
* @return mixed The query result * @return mixed The query result
*/ */
private function _dbCall() private function _dbCall()