2013-01-05 01:14:02 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OAuth2;
|
|
|
|
|
2013-01-29 19:46:47 +05:30
|
|
|
use OAuth2\Storage\SessionInterface;
|
|
|
|
use OAuth2\Storage\ClientInterface;
|
|
|
|
use OAuth2\Storage\ScopeInterface;
|
|
|
|
|
2013-01-22 22:03:09 +05:30
|
|
|
class AuthServer
|
2013-01-05 01:14:02 +05:30
|
|
|
{
|
|
|
|
protected $scopeDelimeter = ',';
|
|
|
|
|
|
|
|
protected $expiresIn = 3600;
|
|
|
|
|
|
|
|
protected $responseTypes = array(
|
|
|
|
'code'
|
|
|
|
);
|
|
|
|
|
|
|
|
protected $storages = array();
|
|
|
|
|
|
|
|
protected $grantTypes = array();
|
|
|
|
|
2013-01-22 21:55:51 +05:30
|
|
|
protected $request = null;
|
|
|
|
|
2013-01-05 01:14:02 +05:30
|
|
|
|
2013-01-29 19:46:47 +05:30
|
|
|
public function __construct(ClientInterface $client, SessionInterface $session, ScopeInterface $scope)
|
|
|
|
{
|
|
|
|
$this->storages = array(
|
|
|
|
'client' => $client,
|
|
|
|
'session' => $session,
|
|
|
|
'scope' => $scope
|
|
|
|
);
|
2013-01-05 01:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public function addGrantType(GrantTypeInterface $grant_type, $identifier = null)
|
|
|
|
{
|
|
|
|
if (is_null($identifier)) {
|
|
|
|
$identifier = $grant_type->getIdentifier();
|
|
|
|
}
|
|
|
|
$this->grantTypes[$identifier] = $grant_type;
|
|
|
|
}
|
|
|
|
|
2013-01-22 21:55:51 +05:30
|
|
|
public function getScopeDelimeter()
|
|
|
|
{
|
|
|
|
return $this->scopeDelimeter;
|
|
|
|
}
|
|
|
|
|
2013-01-05 01:14:02 +05:30
|
|
|
public function setScopeDelimeter($scope_delimeter)
|
|
|
|
{
|
|
|
|
$this->scopeDelimeter = $scope_delimeter;
|
|
|
|
}
|
|
|
|
|
2013-01-22 21:55:51 +05:30
|
|
|
public function getExpiresIn()
|
|
|
|
{
|
|
|
|
return $this->expiresIn;
|
|
|
|
}
|
|
|
|
|
2013-01-05 01:14:02 +05:30
|
|
|
public function setExpiresIn($expires_in)
|
|
|
|
{
|
|
|
|
$this->expiresIn = $expires_in;
|
|
|
|
}
|
|
|
|
|
2013-01-22 21:55:51 +05:30
|
|
|
/**
|
|
|
|
* Sets the Request Object
|
|
|
|
*
|
|
|
|
* @param RequestInterface The Request Object
|
|
|
|
*/
|
|
|
|
public function setRequest(RequestInterface $request)
|
|
|
|
{
|
|
|
|
$this->request = $request;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Request object. It will create one from the globals if one is not set.
|
|
|
|
*
|
|
|
|
* @return RequestInterface
|
|
|
|
*/
|
|
|
|
public function getRequest()
|
|
|
|
{
|
|
|
|
if ($this->request === null) {
|
|
|
|
$this->request = Request::buildFromGlobals();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->request;
|
|
|
|
}
|
|
|
|
|
2013-01-29 19:46:47 +05:30
|
|
|
public function getStorage($obj)
|
|
|
|
{
|
|
|
|
return $this->storages[$obj];
|
|
|
|
}
|
|
|
|
|
2013-01-22 21:55:51 +05:30
|
|
|
/**
|
|
|
|
* Check client authorise parameters
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $authParams Optional array of parsed $_GET keys
|
|
|
|
* @return array Authorise request parameters
|
|
|
|
*/
|
|
|
|
public function checkClientAuthoriseParams($authParams = null)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a new authorise request
|
|
|
|
*
|
|
|
|
* @param string $type The session owner's type
|
|
|
|
* @param string $typeId The session owner's ID
|
|
|
|
* @param array $authoriseParams The authorise request $_GET parameters
|
|
|
|
* @return string An authorisation code
|
|
|
|
*/
|
|
|
|
public function newAuthoriseRequest($type, $typeId, $authoriseParams)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Issue an access token
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $authParams Optional array of parsed $_POST keys
|
|
|
|
* @return array Authorise request parameters
|
|
|
|
*/
|
|
|
|
public function issueAccessToken($authParams = null)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function getCurrentGrantType()
|
|
|
|
{
|
|
|
|
$grantType = $this->getRequest()->post('grant_type');
|
|
|
|
|
|
|
|
if (is_null($grantType)) {
|
|
|
|
throw new Exception
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-05 01:14:02 +05:30
|
|
|
}
|