mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-15 17:56:14 +05:30
Updated grantTypes to use AuthServer::getParam()
This commit is contained in:
parent
92ce378a93
commit
246732153c
@ -1,4 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* OAuth 2.0 Auth code grant
|
||||||
|
*
|
||||||
|
* @package lncd/oauth2
|
||||||
|
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||||
|
* @copyright Copyright (c) 2013 University of Lincoln
|
||||||
|
* @license http://mit-license.org/
|
||||||
|
* @link http://github.com/lncd/oauth2
|
||||||
|
*/
|
||||||
|
|
||||||
namespace OAuth2\Grant;
|
namespace OAuth2\Grant;
|
||||||
|
|
||||||
@ -10,42 +19,60 @@ use OAuth2\Storage\SessionInterface;
|
|||||||
use OAuth2\Storage\ClientInterface;
|
use OAuth2\Storage\ClientInterface;
|
||||||
use OAuth2\Storage\ScopeInterface;
|
use OAuth2\Storage\ScopeInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client credentials grant class
|
||||||
|
*/
|
||||||
class ClientCredentials implements GrantTypeInterface {
|
class ClientCredentials implements GrantTypeInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grant identifier
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $identifier = 'client_credentials';
|
protected $identifier = 'client_credentials';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response type
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $responseType = null;
|
protected $responseType = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the identifier
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getIdentifier()
|
public function getIdentifier()
|
||||||
{
|
{
|
||||||
return $this->identifier;
|
return $this->identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the response type
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getResponseType()
|
public function getResponseType()
|
||||||
{
|
{
|
||||||
return $this->responseType;
|
return $this->responseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function completeFlow($inputParams = null, $authParams = array())
|
/**
|
||||||
|
* Complete the client credentials grant
|
||||||
|
* @param null|array $inputParams
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function completeFlow($inputParams = null)
|
||||||
{
|
{
|
||||||
// Client ID
|
// Get the required params
|
||||||
$authParams['client_id'] = (isset($inputParams['client_id'])) ?
|
$authParams = AuthServer::getParam(array('client_id', 'client_secret'), 'post', $inputParams);
|
||||||
$inputParams['client_id'] :
|
|
||||||
AuthServer::getRequest()->post('client_id');
|
|
||||||
|
|
||||||
if (is_null($authParams['client_id'])) {
|
if (is_null($authParams['client_id'])) {
|
||||||
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_id'), 0);
|
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_id'), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client secret
|
|
||||||
$authParams['client_secret'] = (isset($inputParams['client_secret'])) ?
|
|
||||||
$inputParams['client_secret'] :
|
|
||||||
AuthServer::getRequest()->post('client_secret');
|
|
||||||
|
|
||||||
if (is_null($authParams['client_secret'])) {
|
if (is_null($authParams['client_secret'])) {
|
||||||
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_secret'), 0);
|
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_secret'), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate client ID and redirect URI
|
// Validate client ID and client secret
|
||||||
$clientDetails = AuthServer::getStorage('client')->getClient($authParams['client_id'], $authParams['client_secret']);
|
$clientDetails = AuthServer::getStorage('client')->getClient($authParams['client_id'], $authParams['client_secret']);
|
||||||
|
|
||||||
if ($clientDetails === false) {
|
if ($clientDetails === false) {
|
||||||
|
@ -1,4 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* OAuth 2.0 Password grant
|
||||||
|
*
|
||||||
|
* @package lncd/oauth2
|
||||||
|
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||||
|
* @copyright Copyright (c) 2013 University of Lincoln
|
||||||
|
* @license http://mit-license.org/
|
||||||
|
* @link http://github.com/lncd/oauth2
|
||||||
|
*/
|
||||||
|
|
||||||
namespace OAuth2\Grant;
|
namespace OAuth2\Grant;
|
||||||
|
|
||||||
@ -10,27 +19,60 @@ use OAuth2\Storage\SessionInterface;
|
|||||||
use OAuth2\Storage\ClientInterface;
|
use OAuth2\Storage\ClientInterface;
|
||||||
use OAuth2\Storage\ScopeInterface;
|
use OAuth2\Storage\ScopeInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password grant class
|
||||||
|
*/
|
||||||
class Password implements GrantTypeInterface {
|
class Password implements GrantTypeInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grant identifier
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $identifier = 'password';
|
protected $identifier = 'password';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response type
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $responseType = null;
|
protected $responseType = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback to authenticate a user's name and password
|
||||||
|
* @var function
|
||||||
|
*/
|
||||||
protected $callback = null;
|
protected $callback = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the identifier
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getIdentifier()
|
public function getIdentifier()
|
||||||
{
|
{
|
||||||
return $this->identifier;
|
return $this->identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the response type
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getResponseType()
|
public function getResponseType()
|
||||||
{
|
{
|
||||||
return $this->responseType;
|
return $this->responseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the callback to verify a user's username and password
|
||||||
|
* @param function $callback The callback function
|
||||||
|
*/
|
||||||
public function setVerifyCredentialsCallback($callback)
|
public function setVerifyCredentialsCallback($callback)
|
||||||
{
|
{
|
||||||
$this->callback = $callback;
|
$this->callback = $callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the callback function
|
||||||
|
* @return function
|
||||||
|
*/
|
||||||
protected function getVerifyCredentialsCallback()
|
protected function getVerifyCredentialsCallback()
|
||||||
{
|
{
|
||||||
if (is_null($this->callback) || ! is_callable($this->callback)) {
|
if (is_null($this->callback) || ! is_callable($this->callback)) {
|
||||||
@ -40,22 +82,20 @@ class Password implements GrantTypeInterface {
|
|||||||
return $this->callback;
|
return $this->callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function completeFlow($inputParams = null, $authParams = array())
|
/**
|
||||||
|
* Complete the password grant
|
||||||
|
* @param null|array $inputParams
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function completeFlow($inputParams = null)
|
||||||
{
|
{
|
||||||
// Client ID
|
// Get the required params
|
||||||
$authParams['client_id'] = (isset($inputParams['client_id'])) ?
|
$authParams = AuthServer::getParam(array('client_id', 'client_secret', 'username', 'password'), 'post', $inputParams);
|
||||||
$inputParams['client_id'] :
|
|
||||||
AuthServer::getRequest()->post('client_id');
|
|
||||||
|
|
||||||
if (is_null($authParams['client_id'])) {
|
if (is_null($authParams['client_id'])) {
|
||||||
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_id'), 0);
|
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_id'), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client secret
|
|
||||||
$authParams['client_secret'] = (isset($inputParams['client_secret'])) ?
|
|
||||||
$inputParams['client_secret'] :
|
|
||||||
AuthServer::getRequest()->post('client_secret');
|
|
||||||
|
|
||||||
if (is_null($authParams['client_secret'])) {
|
if (is_null($authParams['client_secret'])) {
|
||||||
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_secret'), 0);
|
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_secret'), 0);
|
||||||
}
|
}
|
||||||
@ -69,20 +109,10 @@ class Password implements GrantTypeInterface {
|
|||||||
|
|
||||||
$authParams['client_details'] = $clientDetails;
|
$authParams['client_details'] = $clientDetails;
|
||||||
|
|
||||||
// User's username
|
|
||||||
$authParams['username'] = (isset($inputParams['username'])) ?
|
|
||||||
$inputParams['username'] :
|
|
||||||
AuthServer::getRequest()->post('username');
|
|
||||||
|
|
||||||
if (is_null($authParams['username'])) {
|
if (is_null($authParams['username'])) {
|
||||||
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'username'), 0);
|
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'username'), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// User's password
|
|
||||||
$authParams['password'] = (isset($inputParams['password'])) ?
|
|
||||||
$inputParams['password'] :
|
|
||||||
AuthServer::getRequest()->post('password');
|
|
||||||
|
|
||||||
if (is_null($authParams['password'])) {
|
if (is_null($authParams['password'])) {
|
||||||
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'password'), 0);
|
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'password'), 0);
|
||||||
}
|
}
|
||||||
|
@ -27,25 +27,18 @@ class RefreshToken implements GrantTypeInterface {
|
|||||||
|
|
||||||
public function completeFlow($inputParams = null, $authParams = array())
|
public function completeFlow($inputParams = null, $authParams = array())
|
||||||
{
|
{
|
||||||
// Client ID
|
// Get the required params
|
||||||
$authParams['client_id'] = (isset($inputParams['client_id'])) ?
|
$authParams = AuthServer::getParam(array('client_id', 'client_secret', 'refresh_token'), 'post', $inputParams);
|
||||||
$inputParams['client_id'] :
|
|
||||||
AuthServer::getRequest()->post('client_id');
|
|
||||||
|
|
||||||
if (is_null($authParams['client_id'])) {
|
if (is_null($authParams['client_id'])) {
|
||||||
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_id'), 0);
|
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_id'), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client secret
|
|
||||||
$authParams['client_secret'] = (isset($inputParams['client_secret'])) ?
|
|
||||||
$inputParams['client_secret'] :
|
|
||||||
AuthServer::getRequest()->post('client_secret');
|
|
||||||
|
|
||||||
if (is_null($authParams['client_secret'])) {
|
if (is_null($authParams['client_secret'])) {
|
||||||
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_secret'), 0);
|
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_secret'), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate client ID and redirect URI
|
// Validate client ID and client secret
|
||||||
$clientDetails = AuthServer::getStorage('client')->getClient($authParams['client_id'], $authParams['client_secret']);
|
$clientDetails = AuthServer::getStorage('client')->getClient($authParams['client_id'], $authParams['client_secret']);
|
||||||
|
|
||||||
if ($clientDetails === false) {
|
if ($clientDetails === false) {
|
||||||
@ -54,11 +47,6 @@ class RefreshToken implements GrantTypeInterface {
|
|||||||
|
|
||||||
$authParams['client_details'] = $clientDetails;
|
$authParams['client_details'] = $clientDetails;
|
||||||
|
|
||||||
// Refresh token
|
|
||||||
$authParams['refresh_token'] = (isset($inputParams['refresh_token'])) ?
|
|
||||||
$inputParams['refresh_token'] :
|
|
||||||
AuthServer::getRequest()->post('refresh_token');
|
|
||||||
|
|
||||||
if (is_null($authParams['refresh_token'])) {
|
if (is_null($authParams['refresh_token'])) {
|
||||||
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'refresh_token'), 0);
|
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'refresh_token'), 0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user