2013-12-02 18:42:54 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2014-01-08 16:15:29 +00:00
|
|
|
* OAuth 2.0 Abstract grant
|
2013-12-02 18:42:54 +00:00
|
|
|
*
|
2014-01-08 16:15:29 +00:00
|
|
|
* @package league/oauth2-server
|
2013-12-02 18:42:54 +00:00
|
|
|
* @author Alex Bilbie <hello@alexbilbie.com>
|
2014-03-09 19:34:23 +00:00
|
|
|
* @copyright Copyright (c) Alex Bilbie
|
2013-12-02 18:42:54 +00:00
|
|
|
* @license http://mit-license.org/
|
2014-03-09 20:05:38 +00:00
|
|
|
* @link https://github.com/thephpleague/oauth2-server
|
2013-12-02 18:42:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace League\OAuth2\Server\Grant;
|
|
|
|
|
2015-04-05 17:01:19 +01:00
|
|
|
use League\Event\Emitter;
|
|
|
|
use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface;
|
|
|
|
use League\OAuth2\Server\Entities\ScopeEntity;
|
2014-04-25 11:24:48 +01:00
|
|
|
use League\OAuth2\Server\Exception;
|
2015-04-05 17:01:19 +01:00
|
|
|
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
|
|
|
|
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
|
|
|
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
2013-12-05 20:25:50 +00:00
|
|
|
|
2014-01-08 16:15:29 +00:00
|
|
|
/**
|
|
|
|
* Abstract grant class
|
|
|
|
*/
|
|
|
|
abstract class AbstractGrant implements GrantTypeInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Grant identifier
|
2014-12-10 13:10:35 +00:00
|
|
|
*
|
2014-01-08 16:15:29 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $identifier = '';
|
2013-12-02 18:42:54 +00:00
|
|
|
|
2013-12-05 20:25:50 +00:00
|
|
|
/**
|
2015-04-05 17:01:19 +01:00
|
|
|
* Grant responds with
|
2014-12-10 13:10:35 +00:00
|
|
|
*
|
2014-01-08 16:15:29 +00:00
|
|
|
* @var string
|
2013-12-05 20:25:50 +00:00
|
|
|
*/
|
2015-04-05 17:01:19 +01:00
|
|
|
protected $respondsWith = 'token';
|
2014-01-08 16:15:29 +00:00
|
|
|
|
|
|
|
/**
|
2015-04-05 17:01:19 +01:00
|
|
|
* @var \Symfony\Component\HttpFoundation\Request
|
2014-01-08 16:15:29 +00:00
|
|
|
*/
|
2015-04-05 17:01:19 +01:00
|
|
|
protected $request;
|
2014-01-08 16:15:29 +00:00
|
|
|
|
|
|
|
/**
|
2015-04-05 17:01:19 +01:00
|
|
|
* @var ClientRepositoryInterface
|
2014-01-08 16:15:29 +00:00
|
|
|
*/
|
2015-04-05 17:01:19 +01:00
|
|
|
protected $clientRepository;
|
2013-12-05 20:25:50 +00:00
|
|
|
|
2013-12-02 18:42:54 +00:00
|
|
|
/**
|
2015-04-05 17:01:19 +01:00
|
|
|
* @var AccessTokenRepositoryInterface
|
2013-12-02 18:42:54 +00:00
|
|
|
*/
|
2015-04-05 17:01:19 +01:00
|
|
|
protected $accessTokenRepository;
|
2013-12-02 18:42:54 +00:00
|
|
|
|
2013-12-04 17:23:19 -05:00
|
|
|
/**
|
2015-04-05 17:01:19 +01:00
|
|
|
* @var \League\Event\Emitter
|
2013-12-04 17:23:19 -05:00
|
|
|
*/
|
2015-04-05 17:01:19 +01:00
|
|
|
protected $emitter;
|
2013-12-05 20:28:31 +00:00
|
|
|
|
2013-12-02 18:42:54 +00:00
|
|
|
/**
|
2015-04-05 17:01:19 +01:00
|
|
|
* @var ScopeRepositoryInterface
|
2013-12-02 18:42:54 +00:00
|
|
|
*/
|
2015-04-05 17:01:19 +01:00
|
|
|
protected $scopeRepository;
|
2013-12-02 18:42:54 +00:00
|
|
|
|
2014-09-11 13:39:50 +01:00
|
|
|
/**
|
2015-04-05 17:01:19 +01:00
|
|
|
* @param \League\Event\Emitter $emitter
|
|
|
|
* @param \League\OAuth2\Server\Repositories\ClientRepositoryInterface $clientRepository
|
|
|
|
* @param \League\OAuth2\Server\Repositories\ScopeRepositoryInterface $scopeRepository
|
|
|
|
* @param \League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface $accessTokenRepository
|
2014-09-11 13:39:50 +01:00
|
|
|
*/
|
2015-04-05 17:01:19 +01:00
|
|
|
public function __construct(
|
|
|
|
Emitter $emitter,
|
|
|
|
ClientRepositoryInterface $clientRepository,
|
|
|
|
ScopeRepositoryInterface $scopeRepository,
|
|
|
|
AccessTokenRepositoryInterface $accessTokenRepository
|
|
|
|
) {
|
|
|
|
$this->emitter = $emitter;
|
|
|
|
$this->clientRepository = $clientRepository;
|
|
|
|
$this->scopeRepository = $scopeRepository;
|
|
|
|
$this->accessTokenRepository = $accessTokenRepository;
|
2014-09-11 13:39:50 +01:00
|
|
|
}
|
|
|
|
|
2013-12-02 18:42:54 +00:00
|
|
|
/**
|
2015-04-05 17:01:19 +01:00
|
|
|
* {@inheritdoc}
|
2013-12-02 18:42:54 +00:00
|
|
|
*/
|
2015-04-05 17:01:19 +01:00
|
|
|
public function getIdentifier()
|
2013-12-02 18:42:54 +00:00
|
|
|
{
|
2015-04-05 17:01:19 +01:00
|
|
|
return $this->identifier;
|
2013-12-02 18:42:54 +00:00
|
|
|
}
|
|
|
|
|
2013-12-05 20:25:50 +00:00
|
|
|
/**
|
2014-11-21 00:06:01 +00:00
|
|
|
* {@inheritdoc}
|
2013-12-05 20:25:50 +00:00
|
|
|
*/
|
2015-04-05 17:01:19 +01:00
|
|
|
public function respondsWith()
|
2013-12-05 20:25:50 +00:00
|
|
|
{
|
2015-04-05 17:01:19 +01:00
|
|
|
return $this->respondsWith;
|
2013-12-05 20:25:50 +00:00
|
|
|
}
|
|
|
|
|
2014-01-08 16:15:29 +00:00
|
|
|
/**
|
2015-04-05 17:01:19 +01:00
|
|
|
* @param string $scopeParamValue A string containing a delimited set of scope identifiers
|
|
|
|
* @param string $scopeDelimiter The delimiter between the scopes in the value string
|
|
|
|
* @param ClientEntityInterface $client
|
|
|
|
* @param string $redirectUri
|
2014-12-10 13:10:35 +00:00
|
|
|
*
|
2015-04-05 17:01:19 +01:00
|
|
|
* @return \League\OAuth2\Server\Entities\ScopeEntity[]
|
|
|
|
* @throws \League\OAuth2\Server\Exception\InvalidScopeException
|
2014-01-08 16:15:29 +00:00
|
|
|
*/
|
2015-04-05 17:01:19 +01:00
|
|
|
public function validateScopes(
|
|
|
|
$scopeParamValue,
|
|
|
|
$scopeDelimiter,
|
|
|
|
ClientEntityInterface $client,
|
|
|
|
$redirectUri = null
|
|
|
|
) {
|
|
|
|
$scopesList = explode($scopeDelimiter, trim($scopeParamValue));
|
2013-12-24 17:01:56 +00:00
|
|
|
|
|
|
|
for ($i = 0; $i < count($scopesList); $i++) {
|
|
|
|
$scopesList[$i] = trim($scopesList[$i]);
|
2014-05-03 11:08:33 +01:00
|
|
|
if ($scopesList[$i] === '') {
|
|
|
|
unset($scopesList[$i]); // Remove any junk scopes
|
|
|
|
}
|
2013-12-24 17:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scopes = [];
|
|
|
|
foreach ($scopesList as $scopeItem) {
|
2015-04-05 17:01:19 +01:00
|
|
|
$scope = $this->scopeRepository->get(
|
2013-12-24 17:01:56 +00:00
|
|
|
$scopeItem,
|
2014-09-30 23:55:21 +01:00
|
|
|
$this->getIdentifier(),
|
2015-04-05 17:01:19 +01:00
|
|
|
$client->getIdentifier()
|
2013-12-24 17:01:56 +00:00
|
|
|
);
|
|
|
|
|
2014-05-02 17:21:53 +01:00
|
|
|
if (($scope instanceof ScopeEntity) === false) {
|
2014-11-08 17:03:15 +00:00
|
|
|
throw new Exception\InvalidScopeException($scopeItem, $redirectUri);
|
2013-12-24 17:01:56 +00:00
|
|
|
}
|
|
|
|
|
2015-04-05 17:01:19 +01:00
|
|
|
$scopes[] = $scope;
|
2014-01-10 12:30:13 +00:00
|
|
|
}
|
2014-05-03 10:53:43 +01:00
|
|
|
|
2014-01-10 12:30:13 +00:00
|
|
|
return $scopes;
|
|
|
|
}
|
2013-12-04 17:23:19 -05:00
|
|
|
}
|