mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-01 16:33:07 +05:30
Merge branch 'release/0.3.4'
This commit is contained in:
commit
1be25955d6
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "lncd/oauth2",
|
"name": "lncd/oauth2",
|
||||||
"description": "OAuth 2.0 Framework",
|
"description": "OAuth 2.0 Framework",
|
||||||
"version": "0.3.3",
|
"version": "0.3.4",
|
||||||
"homepage": "https://github.com/lncd/OAuth2",
|
"homepage": "https://github.com/lncd/OAuth2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -41,7 +41,7 @@ class Server
|
|||||||
private $_responseTypes = array(
|
private $_responseTypes = array(
|
||||||
'code'
|
'code'
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supported grant types
|
* Supported grant types
|
||||||
* @var array
|
* @var array
|
||||||
@ -69,9 +69,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(
|
||||||
@ -89,7 +89,7 @@ class Server
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param array $options Optional list of options to overwrite the defaults
|
* @param array $options Optional list of options to overwrite the defaults
|
||||||
* @return void
|
* @return void
|
||||||
@ -103,7 +103,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
|
||||||
@ -115,7 +115,7 @@ class Server
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check client authorise parameters
|
* Check client authorise parameters
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param array $authParams Optional array of parsed $_GET keys
|
* @param array $authParams Optional array of parsed $_GET keys
|
||||||
* @return array Authorise request parameters
|
* @return array Authorise request parameters
|
||||||
@ -132,7 +132,7 @@ class Server
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
$params['client_id'] = (isset($authParams['client_id'])) ?
|
$params['client_id'] = (isset($authParams['client_id'])) ?
|
||||||
$authParams['client_id'] :
|
$authParams['client_id'] :
|
||||||
$_GET['client_id'];
|
$_GET['client_id'];
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -163,6 +163,8 @@ class Server
|
|||||||
throw new ClientException($this->errors['invalid_client'], 8);
|
throw new ClientException($this->errors['invalid_client'], 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$params['client_details'] = $clientDetails;
|
||||||
|
|
||||||
// Response type
|
// Response type
|
||||||
if ( ! isset($authParams['response_type']) && ! isset($_GET['response_type'])) {
|
if ( ! isset($authParams['response_type']) && ! isset($_GET['response_type'])) {
|
||||||
|
|
||||||
@ -214,7 +216,7 @@ class Server
|
|||||||
'getScope',
|
'getScope',
|
||||||
$scope
|
$scope
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($scopeDetails === false) {
|
if ($scopeDetails === false) {
|
||||||
|
|
||||||
throw new ClientException(sprintf($this->errors['invalid_scope'], $scope), 4);
|
throw new ClientException(sprintf($this->errors['invalid_scope'], $scope), 4);
|
||||||
@ -231,7 +233,7 @@ class Server
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a new authorise request
|
* Parse a new authorise request
|
||||||
*
|
*
|
||||||
* @param string $type The session owner's type
|
* @param string $type The session owner's type
|
||||||
* @param string $typeId The session owner's ID
|
* @param string $typeId The session owner's ID
|
||||||
* @param array $authoriseParams The authorise request $_GET parameters
|
* @param array $authoriseParams The authorise request $_GET parameters
|
||||||
@ -249,10 +251,10 @@ class Server
|
|||||||
|
|
||||||
// Create the new auth code
|
// Create the new auth code
|
||||||
$authCode = $this->newAuthCode(
|
$authCode = $this->newAuthCode(
|
||||||
$authoriseParams['client_id'],
|
$authoriseParams['client_id'],
|
||||||
'user',
|
'user',
|
||||||
$typeId,
|
$typeId,
|
||||||
$authoriseParams['redirect_uri'],
|
$authoriseParams['redirect_uri'],
|
||||||
$authoriseParams['scopes']
|
$authoriseParams['scopes']
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -261,9 +263,9 @@ class Server
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a unique code
|
* Generate a unique code
|
||||||
*
|
*
|
||||||
* Generate a unique code for an authorisation code, or token
|
* Generate a unique code for an authorisation code, or token
|
||||||
*
|
*
|
||||||
* @return string A unique code
|
* @return string A unique code
|
||||||
*/
|
*/
|
||||||
private function generateCode()
|
private function generateCode()
|
||||||
@ -273,7 +275,7 @@ class Server
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new authorisation code
|
* Create a new authorisation code
|
||||||
*
|
*
|
||||||
* @param string $clientId The client ID
|
* @param string $clientId The client ID
|
||||||
* @param string $type The type of the owner of the session
|
* @param string $type The type of the owner of the session
|
||||||
* @param string $typeId The session owner's ID
|
* @param string $typeId The session owner's ID
|
||||||
@ -286,7 +288,7 @@ class Server
|
|||||||
{
|
{
|
||||||
$authCode = $this->generateCode();
|
$authCode = $this->generateCode();
|
||||||
|
|
||||||
// If an access token exists then update the existing session with the
|
// If an access token exists then update the existing session with the
|
||||||
// new authorisation code otherwise create a new session
|
// new authorisation code otherwise create a new session
|
||||||
if ($accessToken !== null) {
|
if ($accessToken !== null) {
|
||||||
|
|
||||||
@ -299,13 +301,13 @@ class Server
|
|||||||
$accessToken,
|
$accessToken,
|
||||||
'requested'
|
'requested'
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Delete any existing sessions just to be sure
|
// Delete any existing sessions just to be sure
|
||||||
$this->_dbCall('deleteSession', $clientId, $type, $typeId);
|
$this->_dbCall('deleteSession', $clientId, $type, $typeId);
|
||||||
|
|
||||||
// Create a new session
|
// Create a new session
|
||||||
$sessionId = $this->_dbCall(
|
$sessionId = $this->_dbCall(
|
||||||
'newSession',
|
'newSession',
|
||||||
$clientId,
|
$clientId,
|
||||||
@ -317,7 +319,7 @@ class Server
|
|||||||
null,
|
null,
|
||||||
'requested'
|
'requested'
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add the scopes
|
// Add the scopes
|
||||||
foreach ($scopes as $key => $scope) {
|
foreach ($scopes as $key => $scope) {
|
||||||
|
|
||||||
@ -330,17 +332,17 @@ class Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $authCode;
|
return $authCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Issue an access token
|
* Issue an access token
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
*
|
*
|
||||||
* @param array $authParams Optional array of parsed $_POST keys
|
* @param array $authParams Optional array of parsed $_POST keys
|
||||||
*
|
*
|
||||||
* @return array Authorise request parameters
|
* @return array Authorise request parameters
|
||||||
*/
|
*/
|
||||||
public function issueAccessToken($authParams = null)
|
public function issueAccessToken($authParams = null)
|
||||||
@ -367,10 +369,10 @@ class Server
|
|||||||
|
|
||||||
switch ($params['grant_type'])
|
switch ($params['grant_type'])
|
||||||
{
|
{
|
||||||
|
|
||||||
case 'authorization_code': // Authorization code grant
|
case 'authorization_code': // Authorization code grant
|
||||||
return $this->completeAuthCodeGrant($authParams, $params);
|
return $this->completeAuthCodeGrant($authParams, $params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'refresh_token': // Refresh token
|
case 'refresh_token': // Refresh token
|
||||||
case 'password': // Resource owner password credentials grant
|
case 'password': // Resource owner password credentials grant
|
||||||
@ -383,12 +385,12 @@ class Server
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Complete the authorisation code grant
|
* Complete the authorisation code grant
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
*
|
*
|
||||||
* @param array $authParams Array of parsed $_POST keys
|
* @param array $authParams Array of parsed $_POST keys
|
||||||
* @param array $params Generated parameters from issueAccessToken()
|
* @param array $params Generated parameters from issueAccessToken()
|
||||||
*
|
*
|
||||||
* @return array Authorise request parameters
|
* @return array Authorise request parameters
|
||||||
*/
|
*/
|
||||||
private function completeAuthCodeGrant($authParams = array(), $params = array())
|
private function completeAuthCodeGrant($authParams = array(), $params = array())
|
||||||
@ -436,7 +438,7 @@ class Server
|
|||||||
$clientDetails = $this->_dbCall(
|
$clientDetails = $this->_dbCall(
|
||||||
'validateClient',
|
'validateClient',
|
||||||
$params['client_id'],
|
$params['client_id'],
|
||||||
$params['client_secret'],
|
$params['client_secret'],
|
||||||
$params['redirect_uri']
|
$params['redirect_uri']
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -470,7 +472,7 @@ class Server
|
|||||||
if ( ! $session) {
|
if ( ! $session) {
|
||||||
|
|
||||||
throw new ClientException(sprintf($this->errors['invalid_grant'], 'code'), 9);
|
throw new ClientException(sprintf($this->errors['invalid_grant'], 'code'), 9);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// A session ID was returned so update it with an access token,
|
// A session ID was returned so update it with an access token,
|
||||||
@ -508,16 +510,16 @@ class Server
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the redirect uri with appended params
|
* Generates the redirect uri with appended params
|
||||||
*
|
*
|
||||||
* @param string $redirectUri The redirect URI
|
* @param string $redirectUri The redirect URI
|
||||||
* @param array $params The parameters to be appended to the URL
|
* @param array $params The parameters to be appended to the URL
|
||||||
* @param string $query_delimeter The query string delimiter (default: ?)
|
* @param string $query_delimeter The query string delimiter (default: ?)
|
||||||
*
|
*
|
||||||
* @return string The updated redirect URI
|
* @return string The updated redirect URI
|
||||||
*/
|
*/
|
||||||
public function redirectUri($redirectUri, $params = array(), $queryDelimeter = '?')
|
public function redirectUri($redirectUri, $params = array(), $queryDelimeter = '?')
|
||||||
{
|
{
|
||||||
|
|
||||||
if (strstr($redirectUri, $queryDelimeter)) {
|
if (strstr($redirectUri, $queryDelimeter)) {
|
||||||
|
|
||||||
$redirectUri = $redirectUri . '&' . http_build_query($params);
|
$redirectUri = $redirectUri . '&' . http_build_query($params);
|
||||||
@ -527,14 +529,14 @@ class Server
|
|||||||
$redirectUri = $redirectUri . $queryDelimeter . http_build_query($params);
|
$redirectUri = $redirectUri . $queryDelimeter . http_build_query($params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $redirectUri;
|
return $redirectUri;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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()
|
||||||
|
Loading…
Reference in New Issue
Block a user