diff --git a/master/AbstractServer.php.html b/master/AbstractServer.php.html new file mode 100644 index 00000000..7b3488cf --- /dev/null +++ b/master/AbstractServer.php.html @@ -0,0 +1,905 @@ + + +
+ ++ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 20 / 20 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 44 / 44 |
+
AbstractServer | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 20 / 20 |
+ 22 | +
+
+
+ |
+ 100.00% |
+ 44 / 44 |
+
__construct() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
setEventEmitter($emitter = null) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+ |||
addEventListener($eventName, callable $listener) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getEventEmitter() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
setRequest($request) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getRequest() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ |||
setClientStorage(ClientInterface $storage) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ |||
setSessionStorage(SessionInterface $storage) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ |||
setAccessTokenStorage(AccessTokenInterface $storage) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ |||
setRefreshTokenStorage(RefreshTokenInterface $storage) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ |||
setAuthCodeStorage(AuthCodeInterface $storage) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ |||
setScopeStorage(ScopeInterface $storage) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ |||
getClientStorage() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getScopeStorage() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getSessionStorage() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getRefreshTokenStorage() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getAccessTokenStorage() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getAuthCodeStorage() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
setTokenType(TokenTypeInterface $tokenType) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ |||
getTokenType() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
<?php | |
/** | |
* OAuth 2.0 Abstract Server | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server; | |
use League\Event\Emitter; | |
use League\OAuth2\Server\Storage\AccessTokenInterface; | |
use League\OAuth2\Server\Storage\AuthCodeInterface; | |
use League\OAuth2\Server\Storage\ClientInterface; | |
use League\OAuth2\Server\Storage\RefreshTokenInterface; | |
use League\OAuth2\Server\Storage\ScopeInterface; | |
use League\OAuth2\Server\Storage\SessionInterface; | |
use League\OAuth2\Server\TokenType\TokenTypeInterface; | |
use Symfony\Component\HttpFoundation\Request; | |
/** | |
* OAuth 2.0 Resource Server | |
*/ | |
abstract class AbstractServer | |
{ | |
/** | |
* The request object | |
* | |
* @var \Symfony\Component\HttpFoundation\Request | |
*/ | |
protected $request; | |
/** | |
* Session storage | |
* | |
* @var \League\OAuth2\Server\Storage\SessionInterface | |
*/ | |
protected $sessionStorage; | |
/** | |
* Access token storage | |
* | |
* @var \League\OAuth2\Server\Storage\AccessTokenInterface | |
*/ | |
protected $accessTokenStorage; | |
/** | |
* Refresh token storage | |
* | |
* @var \League\OAuth2\Server\Storage\RefreshTokenInterface | |
*/ | |
protected $refreshTokenStorage; | |
/** | |
* Auth code storage | |
* | |
* @var \League\OAuth2\Server\Storage\AuthCodeInterface | |
*/ | |
protected $authCodeStorage; | |
/** | |
* Scope storage | |
* | |
* @var \League\OAuth2\Server\Storage\ScopeInterface | |
*/ | |
protected $scopeStorage; | |
/** | |
* Client storage | |
* | |
* @var \League\OAuth2\Server\Storage\ClientInterface | |
*/ | |
protected $clientStorage; | |
/** | |
* Token type | |
* | |
* @var \League\OAuth2\Server\TokenType\TokenTypeInterface | |
*/ | |
protected $tokenType; | |
/** | |
* Event emitter | |
* | |
* @var \League\Event\Emitter | |
*/ | |
protected $eventEmitter; | |
/** | |
* Abstract server constructor | |
*/ | |
public function __construct() | |
{ | |
$this->setEventEmitter(); | |
} | |
/** | |
* Set an event emitter | |
* | |
* @param object $emitter Event emitter object | |
*/ | |
public function setEventEmitter($emitter = null) | |
{ | |
if ($emitter === null) { | |
$this->eventEmitter = new Emitter(); | |
} else { | |
$this->eventEmitter = $emitter; | |
} | |
} | |
/** | |
* Add an event listener to the event emitter | |
* | |
* @param string $eventName Event name | |
* @param callable $listener Callable function or method | |
*/ | |
public function addEventListener($eventName, callable $listener) | |
{ | |
$this->eventEmitter->addListener($eventName, $listener); | |
} | |
/** | |
* Returns the event emitter | |
* | |
* @return \League\Event\Emitter | |
*/ | |
public function getEventEmitter() | |
{ | |
return $this->eventEmitter; | |
} | |
/** | |
* Sets the Request Object | |
* | |
* @param \Symfony\Component\HttpFoundation\Request The Request Object | |
* | |
* @return self | |
*/ | |
public function setRequest($request) | |
{ | |
$this->request = $request; | |
return $this; | |
} | |
/** | |
* Gets the Request object. It will create one from the globals if one is not set. | |
* | |
* @return \Symfony\Component\HttpFoundation\Request | |
*/ | |
public function getRequest() | |
{ | |
if ($this->request === null) { | |
$this->request = Request::createFromGlobals(); | |
} | |
return $this->request; | |
} | |
/** | |
* Set the client storage | |
* | |
* @param \League\OAuth2\Server\Storage\ClientInterface $storage | |
* | |
* @return self | |
*/ | |
public function setClientStorage(ClientInterface $storage) | |
{ | |
$storage->setServer($this); | |
$this->clientStorage = $storage; | |
return $this; | |
} | |
/** | |
* Set the session storage | |
* | |
* @param \League\OAuth2\Server\Storage\SessionInterface $storage | |
* | |
* @return self | |
*/ | |
public function setSessionStorage(SessionInterface $storage) | |
{ | |
$storage->setServer($this); | |
$this->sessionStorage = $storage; | |
return $this; | |
} | |
/** | |
* Set the access token storage | |
* | |
* @param \League\OAuth2\Server\Storage\AccessTokenInterface $storage | |
* | |
* @return self | |
*/ | |
public function setAccessTokenStorage(AccessTokenInterface $storage) | |
{ | |
$storage->setServer($this); | |
$this->accessTokenStorage = $storage; | |
return $this; | |
} | |
/** | |
* Set the refresh token storage | |
* | |
* @param \League\OAuth2\Server\Storage\RefreshTokenInterface $storage | |
* | |
* @return self | |
*/ | |
public function setRefreshTokenStorage(RefreshTokenInterface $storage) | |
{ | |
$storage->setServer($this); | |
$this->refreshTokenStorage = $storage; | |
return $this; | |
} | |
/** | |
* Set the auth code storage | |
* | |
* @param \League\OAuth2\Server\Storage\AuthCodeInterface $storage | |
* | |
* @return self | |
*/ | |
public function setAuthCodeStorage(AuthCodeInterface $storage) | |
{ | |
$storage->setServer($this); | |
$this->authCodeStorage = $storage; | |
return $this; | |
} | |
/** | |
* Set the scope storage | |
* | |
* @param \League\OAuth2\Server\Storage\ScopeInterface $storage | |
* | |
* @return self | |
*/ | |
public function setScopeStorage(ScopeInterface $storage) | |
{ | |
$storage->setServer($this); | |
$this->scopeStorage = $storage; | |
return $this; | |
} | |
/** | |
* Return the client storage | |
* | |
* @return \League\OAuth2\Server\Storage\ClientInterface | |
*/ | |
public function getClientStorage() | |
{ | |
return $this->clientStorage; | |
} | |
/** | |
* Return the scope storage | |
* | |
* @return \League\OAuth2\Server\Storage\ScopeInterface | |
*/ | |
public function getScopeStorage() | |
{ | |
return $this->scopeStorage; | |
} | |
/** | |
* Return the session storage | |
* | |
* @return \League\OAuth2\Server\Storage\SessionInterface | |
*/ | |
public function getSessionStorage() | |
{ | |
return $this->sessionStorage; | |
} | |
/** | |
* Return the refresh token storage | |
* | |
* @return \League\OAuth2\Server\Storage\RefreshTokenInterface | |
*/ | |
public function getRefreshTokenStorage() | |
{ | |
return $this->refreshTokenStorage; | |
} | |
/** | |
* Return the access token storage | |
* | |
* @return \League\OAuth2\Server\Storage\AccessTokenInterface | |
*/ | |
public function getAccessTokenStorage() | |
{ | |
return $this->accessTokenStorage; | |
} | |
/** | |
* Return the auth code storage | |
* | |
* @return \League\OAuth2\Server\Storage\AuthCodeInterface | |
*/ | |
public function getAuthCodeStorage() | |
{ | |
return $this->authCodeStorage; | |
} | |
/** | |
* Set the access token type | |
* | |
* @param TokenTypeInterface $tokenType The token type | |
* | |
* @return void | |
*/ | |
public function setTokenType(TokenTypeInterface $tokenType) | |
{ | |
$tokenType->setServer($this); | |
$this->tokenType = $tokenType; | |
} | |
/** | |
* Get the access token type | |
* | |
* @return TokenTypeInterface | |
*/ | |
public function getTokenType() | |
{ | |
return $this->tokenType; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 16 / 16 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 38 / 38 |
+
AuthorizationServer | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 16 / 16 |
+ 21 | +
+
+
+ |
+ 100.00% |
+ 38 / 38 |
+
__construct() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ |||
addGrantType(GrantTypeInterface $grantType, $identifier = null) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 3 | +
+
+
+ |
+ 100.00% |
+ 9 / 9 |
+ |||
hasGrantType($identifier) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getResponseTypes() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
requireScopeParam($require = true) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
scopeParamRequired() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
setDefaultScope($default = null) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getDefaultScope() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
stateParamRequired() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
requireStateParam($require = true) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getScopeDelimiter() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
setScopeDelimiter($scopeDelimiter = ' ') | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getAccessTokenTTL() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
setAccessTokenTTL($accessTokenTTL = 3600) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
issueAccessToken() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 3 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+ |||
getGrantType($grantType) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
<?php | |
/** | |
* OAuth 2.0 Authorization Server | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server; | |
use League\OAuth2\Server\Grant\GrantTypeInterface; | |
use League\OAuth2\Server\TokenType\Bearer; | |
/** | |
* OAuth 2.0 authorization server class | |
*/ | |
class AuthorizationServer extends AbstractServer | |
{ | |
/** | |
* The delimeter between scopes specified in the scope query string parameter | |
* The OAuth 2 specification states it should be a space but most use a comma | |
* | |
* @var string | |
*/ | |
protected $scopeDelimiter = ' '; | |
/** | |
* The TTL (time to live) of an access token in seconds (default: 3600) | |
* | |
* @var integer | |
*/ | |
protected $accessTokenTTL = 3600; | |
/** | |
* The registered grant response types | |
* | |
* @var array | |
*/ | |
protected $responseTypes = []; | |
/** | |
* The registered grant types | |
* | |
* @var array | |
*/ | |
protected $grantTypes = []; | |
/** | |
* Require the "scope" parameter to be in checkAuthoriseParams() | |
* | |
* @var boolean | |
*/ | |
protected $requireScopeParam = false; | |
/** | |
* Default scope(s) to be used if none is provided | |
* | |
* @var string|array | |
*/ | |
protected $defaultScope; | |
/** | |
* Require the "state" parameter to be in checkAuthoriseParams() | |
* | |
* @var boolean | |
*/ | |
protected $requireStateParam = false; | |
/** | |
* Create a new OAuth2 authorization server | |
* | |
* @return self | |
*/ | |
public function __construct() | |
{ | |
// Set Bearer as the default token type | |
$this->setTokenType(new Bearer()); | |
parent::__construct(); | |
return $this; | |
} | |
/** | |
* Enable support for a grant | |
* | |
* @param GrantTypeInterface $grantType A grant class which conforms to Interface/GrantTypeInterface | |
* @param null|string $identifier An identifier for the grant (autodetected if not passed) | |
* | |
* @return self | |
*/ | |
public function addGrantType(GrantTypeInterface $grantType, $identifier = null) | |
{ | |
if (is_null($identifier)) { | |
$identifier = $grantType->getIdentifier(); | |
} | |
// Inject server into grant | |
$grantType->setAuthorizationServer($this); | |
$this->grantTypes[$identifier] = $grantType; | |
if (!is_null($grantType->getResponseType())) { | |
$this->responseTypes[] = $grantType->getResponseType(); | |
} | |
return $this; | |
} | |
/** | |
* Check if a grant type has been enabled | |
* | |
* @param string $identifier The grant type identifier | |
* | |
* @return boolean Returns "true" if enabled, "false" if not | |
*/ | |
public function hasGrantType($identifier) | |
{ | |
return (array_key_exists($identifier, $this->grantTypes)); | |
} | |
/** | |
* Returns response types | |
* | |
* @return array | |
*/ | |
public function getResponseTypes() | |
{ | |
return $this->responseTypes; | |
} | |
/** | |
* Require the "scope" parameter in checkAuthoriseParams() | |
* | |
* @param boolean $require | |
* | |
* @return self | |
*/ | |
public function requireScopeParam($require = true) | |
{ | |
$this->requireScopeParam = $require; | |
return $this; | |
} | |
/** | |
* Is the scope parameter required? | |
* | |
* @return bool | |
*/ | |
public function scopeParamRequired() | |
{ | |
return $this->requireScopeParam; | |
} | |
/** | |
* Default scope to be used if none is provided and requireScopeParam() is false | |
* | |
* @param string $default Name of the default scope | |
* | |
* @return self | |
*/ | |
public function setDefaultScope($default = null) | |
{ | |
$this->defaultScope = $default; | |
return $this; | |
} | |
/** | |
* Default scope to be used if none is provided and requireScopeParam is false | |
* | |
* @return string|null | |
*/ | |
public function getDefaultScope() | |
{ | |
return $this->defaultScope; | |
} | |
/** | |
* Require the "state" paremter in checkAuthoriseParams() | |
* | |
* @return bool | |
*/ | |
public function stateParamRequired() | |
{ | |
return $this->requireStateParam; | |
} | |
/** | |
* Require the "state" paremter in checkAuthoriseParams() | |
* | |
* @param boolean $require | |
* | |
* @return self | |
*/ | |
public function requireStateParam($require = true) | |
{ | |
$this->requireStateParam = $require; | |
return $this; | |
} | |
/** | |
* Get the scope delimiter | |
* | |
* @return string The scope delimiter (default: ",") | |
*/ | |
public function getScopeDelimiter() | |
{ | |
return $this->scopeDelimiter; | |
} | |
/** | |
* Set the scope delimiter | |
* | |
* @param string $scopeDelimiter | |
* | |
* @return self | |
*/ | |
public function setScopeDelimiter($scopeDelimiter = ' ') | |
{ | |
$this->scopeDelimiter = $scopeDelimiter; | |
return $this; | |
} | |
/** | |
* Get the TTL for an access token | |
* | |
* @return int The TTL | |
*/ | |
public function getAccessTokenTTL() | |
{ | |
return $this->accessTokenTTL; | |
} | |
/** | |
* Set the TTL for an access token | |
* | |
* @param int $accessTokenTTL The new TTL | |
* | |
* @return self | |
*/ | |
public function setAccessTokenTTL($accessTokenTTL = 3600) | |
{ | |
$this->accessTokenTTL = $accessTokenTTL; | |
return $this; | |
} | |
/** | |
* Issue an access token | |
* | |
* @return array Authorise request parameters | |
* | |
* @throws | |
*/ | |
public function issueAccessToken() | |
{ | |
$grantType = $this->getRequest()->request->get('grant_type'); | |
if (is_null($grantType)) { | |
throw new Exception\InvalidRequestException('grant_type'); | |
} | |
// Ensure grant type is one that is recognised and is enabled | |
if (!in_array($grantType, array_keys($this->grantTypes))) { | |
throw new Exception\UnsupportedGrantTypeException($grantType); | |
} | |
// Complete the flow | |
return $this->getGrantType($grantType)->completeFlow(); | |
} | |
/** | |
* Return a grant type class | |
* | |
* @param string $grantType The grant type identifier | |
* | |
* @return Grant\GrantTypeInterface | |
* | |
* @throws | |
*/ | |
public function getGrantType($grantType) | |
{ | |
if (isset($this->grantTypes[$grantType])) { | |
return $this->grantTypes[$grantType]; | |
} | |
throw new Exception\InvalidGrantException($grantType); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
+
+ |
+ 90.00% |
+ 9 / 10 |
+ CRAP | +
+
+
+ |
+ 96.30% |
+ 26 / 27 |
+
AbstractTokenEntity | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
+
+ |
+ 91.67% |
+ 11 / 12 |
+ 18 | +
+
+
+ |
+ 96.30% |
+ 26 / 27 |
+
__construct(AbstractServer $server) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
setSession(SessionEntity $session) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
setExpireTime($expireTime) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getExpireTime() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
isExpired() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
setId($id = null) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getId() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
associateScope(ScopeEntity $scope) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ |||
formatScopes($unformatted = []) | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+ 4.02 | +
+
+
+ |
+ 88.89% |
+ 8 / 9 |
+ |||
__toString() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ |||
expire() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | ++ | + | ||||
save() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | ++ | + |
<?php | |
/** | |
* OAuth 2.0 Abstract token | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Entity; | |
use League\OAuth2\Server\AbstractServer; | |
use League\OAuth2\Server\Util\SecureKey; | |
/** | |
* Abstract token class | |
*/ | |
abstract class AbstractTokenEntity | |
{ | |
/** | |
* Token identifier | |
* | |
* @var string | |
*/ | |
protected $id; | |
/** | |
* Associated session | |
* | |
* @var \League\OAuth2\Server\Entity\SessionEntity | |
*/ | |
protected $session; | |
/** | |
* Session scopes | |
* | |
* @var \League\OAuth2\Server\Entity\ScopeEntity[] | |
*/ | |
protected $scopes; | |
/** | |
* Token expire time | |
* | |
* @var int | |
*/ | |
protected $expireTime = 0; | |
/** | |
* Authorization or resource server | |
* | |
* @var \League\OAuth2\Server\AbstractServer | |
*/ | |
protected $server; | |
/** | |
* __construct | |
* | |
* @param \League\OAuth2\Server\AbstractServer $server | |
* | |
* @return self | |
*/ | |
public function __construct(AbstractServer $server) | |
{ | |
$this->server = $server; | |
return $this; | |
} | |
/** | |
* Set session | |
* | |
* @param \League\OAuth2\Server\Entity\SessionEntity $session | |
* | |
* @return self | |
*/ | |
public function setSession(SessionEntity $session) | |
{ | |
$this->session = $session; | |
return $this; | |
} | |
/** | |
* Set the expire time of the token | |
* | |
* @param integer $expireTime Unix time stamp | |
* | |
* @return self | |
*/ | |
public function setExpireTime($expireTime) | |
{ | |
$this->expireTime = $expireTime; | |
return $this; | |
} | |
/** | |
* Return token expire time | |
* | |
* @return int | |
*/ | |
public function getExpireTime() | |
{ | |
return $this->expireTime; | |
} | |
/** | |
* Is the token expired? | |
* | |
* @return bool | |
*/ | |
public function isExpired() | |
{ | |
return ((time() - $this->expireTime) > 0); | |
} | |
/** | |
* Set token ID | |
* | |
* @param string $id Token ID | |
* | |
* @return self | |
*/ | |
public function setId($id = null) | |
{ | |
$this->id = ($id !== null) ? $id : SecureKey::generate(); | |
return $this; | |
} | |
/** | |
* Get the token ID | |
* | |
* @return string | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Associate a scope | |
* | |
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope | |
* | |
* @return self | |
*/ | |
public function associateScope(ScopeEntity $scope) | |
{ | |
if (!isset($this->scopes[$scope->getId()])) { | |
$this->scopes[$scope->getId()] = $scope; | |
} | |
return $this; | |
} | |
/** | |
* Format the local scopes array | |
* | |
* @param \League\OAuth2\Server\Entity\ScopeEntity[] | |
* | |
* @return array | |
*/ | |
protected function formatScopes($unformatted = []) | |
{ | |
if (is_null($unformatted)) { | |
return []; | |
} | |
$scopes = []; | |
foreach ($unformatted as $scope) { | |
if ($scope instanceof ScopeEntity) { | |
$scopes[$scope->getId()] = $scope; | |
} | |
} | |
return $scopes; | |
} | |
/** | |
* Returns the token as a string if the object is cast as a string | |
* | |
* @return string | |
*/ | |
public function __toString() | |
{ | |
if ($this->id === null) { | |
return ''; | |
} | |
return $this->id; | |
} | |
/** | |
* Expire the token | |
* | |
* @return void | |
*/ | |
abstract public function expire(); | |
/** | |
* Save the token | |
* | |
* @return void | |
*/ | |
abstract public function save(); | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
+
+ |
+ 80.00% |
+ 4 / 5 |
+ CRAP | +
+
+
+ |
+ 84.00% |
+ 21 / 25 |
+
AccessTokenEntity | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
+
+ |
+ 80.00% |
+ 4 / 5 |
+ 9.33 | +
+
+
+ |
+ 84.00% |
+ 21 / 25 |
+
getSession() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ |||
hasScope($scope) | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+ 6 | +
+
+
+ |
+ 0.00% |
+ 0 / 4 |
+ |||
getScopes() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+ |||
save() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 9 / 9 |
+ |||
expire() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
<?php | |
/** | |
* OAuth 2.0 Access token entity | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Entity; | |
/** | |
* Access token entity class | |
*/ | |
class AccessTokenEntity extends AbstractTokenEntity | |
{ | |
/** | |
* Get session | |
* | |
* @return \League\OAuth2\Server\Entity\SessionEntity | |
*/ | |
public function getSession() | |
{ | |
if ($this->session instanceof SessionEntity) { | |
return $this->session; | |
} | |
$this->session = $this->server->getSessionStorage()->getByAccessToken($this); | |
return $this->session; | |
} | |
/** | |
* Check if access token has an associated scope | |
* | |
* @param string $scope Scope to check | |
* | |
* @return bool | |
*/ | |
public function hasScope($scope) | |
{ | |
if ($this->scopes === null) { | |
$this->getScopes(); | |
} | |
return isset($this->scopes[$scope]); | |
} | |
/** | |
* Return all scopes associated with the access token | |
* | |
* @return \League\OAuth2\Server\Entity\ScopeEntity[] | |
*/ | |
public function getScopes() | |
{ | |
if ($this->scopes === null) { | |
$this->scopes = $this->formatScopes( | |
$this->server->getAccessTokenStorage()->getScopes($this) | |
); | |
} | |
return $this->scopes; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function save() | |
{ | |
$this->server->getAccessTokenStorage()->create( | |
$this->getId(), | |
$this->getExpireTime(), | |
$this->getSession()->getId() | |
); | |
// Associate the scope with the token | |
foreach ($this->getScopes() as $scope) { | |
$this->server->getAccessTokenStorage()->associateScope($this, $scope); | |
} | |
return $this; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function expire() | |
{ | |
$this->server->getAccessTokenStorage()->delete($this); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 31 / 31 |
+
AuthCodeEntity | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+ 11 | +
+
+
+ |
+ 100.00% |
+ 31 / 31 |
+
setRedirectUri($redirectUri) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getRedirectUri() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
generateRedirectUri($state = null, $queryDelimeter = '?') | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+ |||
getSession() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ |||
getScopes() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+ |||
save() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 10 / 10 |
+ |||
expire() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
<?php | |
/** | |
* OAuth 2.0 Auth code entity | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Entity; | |
/** | |
* Access token entity class | |
*/ | |
class AuthCodeEntity extends AbstractTokenEntity | |
{ | |
/** | |
* Redirect URI | |
* | |
* @var string | |
*/ | |
protected $redirectUri = ''; | |
/** | |
* Set the redirect URI for the authorization request | |
* | |
* @param string $redirectUri | |
* | |
* @return self | |
*/ | |
public function setRedirectUri($redirectUri) | |
{ | |
$this->redirectUri = $redirectUri; | |
return $this; | |
} | |
/** | |
* Get the redirect URI | |
* | |
* @return string | |
*/ | |
public function getRedirectUri() | |
{ | |
return $this->redirectUri; | |
} | |
/** | |
* Generate a redirect URI | |
* | |
* @param string $state The state parameter if set by the client | |
* @param string $queryDelimeter The query delimiter ('?' for auth code grant, '#' for implicit grant) | |
* | |
* @return string | |
*/ | |
public function generateRedirectUri($state = null, $queryDelimeter = '?') | |
{ | |
$uri = $this->getRedirectUri(); | |
$uri .= (strstr($this->getRedirectUri(), $queryDelimeter) === false) ? $queryDelimeter : '&'; | |
return $uri.http_build_query([ | |
'code' => $this->getId(), | |
'state' => $state, | |
]); | |
} | |
/** | |
* Get session | |
* | |
* @return \League\OAuth2\Server\Entity\SessionEntity | |
*/ | |
public function getSession() | |
{ | |
if ($this->session instanceof SessionEntity) { | |
return $this->session; | |
} | |
$this->session = $this->server->getSessionStorage()->getByAuthCode($this); | |
return $this->session; | |
} | |
/** | |
* Return all scopes associated with the session | |
* | |
* @return \League\OAuth2\Server\Entity\ScopeEntity[] | |
*/ | |
public function getScopes() | |
{ | |
if ($this->scopes === null) { | |
$this->scopes = $this->formatScopes( | |
$this->server->getAuthCodeStorage()->getScopes($this) | |
); | |
} | |
return $this->scopes; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function save() | |
{ | |
$this->server->getAuthCodeStorage()->create( | |
$this->getId(), | |
$this->getExpireTime(), | |
$this->getSession()->getId(), | |
$this->getRedirectUri() | |
); | |
// Associate the scope with the token | |
foreach ($this->getScopes() as $scope) { | |
$this->server->getAuthCodeStorage()->associateScope($this, $scope); | |
} | |
return $this; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function expire() | |
{ | |
$this->server->getAuthCodeStorage()->delete($this); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
ClientEntity | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+ 5 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
__construct(AbstractServer $server) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getId() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getSecret() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getName() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getRedirectUri() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
<?php | |
/** | |
* OAuth 2.0 Client entity | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Entity; | |
use League\OAuth2\Server\AbstractServer; | |
/** | |
* Client entity class | |
*/ | |
class ClientEntity | |
{ | |
use EntityTrait; | |
/** | |
* Client identifier | |
* | |
* @var string | |
*/ | |
protected $id = null; | |
/** | |
* Client secret | |
* | |
* @var string | |
*/ | |
protected $secret = null; | |
/** | |
* Client name | |
* | |
* @var string | |
*/ | |
protected $name = null; | |
/** | |
* Client redirect URI | |
* | |
* @var string | |
*/ | |
protected $redirectUri = null; | |
/** | |
* Authorization or resource server | |
* | |
* @var \League\OAuth2\Server\AbstractServer | |
*/ | |
protected $server; | |
/** | |
* __construct | |
* | |
* @param \League\OAuth2\Server\AbstractServer $server | |
* | |
* @return self | |
*/ | |
public function __construct(AbstractServer $server) | |
{ | |
$this->server = $server; | |
return $this; | |
} | |
/** | |
* Return the client identifier | |
* | |
* @return string | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Return the client secret | |
* | |
* @return string | |
*/ | |
public function getSecret() | |
{ | |
return $this->secret; | |
} | |
/** | |
* Get the client name | |
* | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return $this->name; | |
} | |
/** | |
* Returnt the client redirect URI | |
* | |
* @return string | |
*/ | |
public function getRedirectUri() | |
{ | |
return $this->redirectUri; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
EntityTrait | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 3 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
hydrate(array $properties) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 3 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
<?php | |
/** | |
* OAuth 2.0 Entity trait | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Entity; | |
trait EntityTrait | |
{ | |
/** | |
* Hydrate an entity with properites | |
* | |
* @param array $properties | |
* | |
* @return self | |
*/ | |
public function hydrate(array $properties) | |
{ | |
foreach ($properties as $prop => $val) { | |
if (property_exists($this, $prop)) { | |
$this->{$prop} = $val; | |
} | |
} | |
return $this; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 16 / 16 |
+
RefreshTokenEntity | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+ 6 | +
+
+
+ |
+ 100.00% |
+ 16 / 16 |
+
setAccessTokenId($accessTokenId) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
setAccessToken(AccessTokenEntity $accessTokenEntity) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getAccessToken() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ |||
save() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+ |||
expire() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
<?php | |
/** | |
* OAuth 2.0 Refresh token entity | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Entity; | |
/** | |
* Refresh token entity class | |
*/ | |
class RefreshTokenEntity extends AbstractTokenEntity | |
{ | |
/** | |
* Access token associated to refresh token | |
* | |
* @var \League\OAuth2\Server\Entity\AccessTokenEntity | |
*/ | |
protected $accessTokenEntity; | |
/** | |
* Id of the access token | |
* | |
* @var string | |
*/ | |
protected $accessTokenId; | |
/** | |
* Set the ID of the associated access token | |
* | |
* @param string $accessTokenId | |
* | |
* @return self | |
*/ | |
public function setAccessTokenId($accessTokenId) | |
{ | |
$this->accessTokenId = $accessTokenId; | |
return $this; | |
} | |
/** | |
* Associate an access token | |
* | |
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessTokenEntity | |
* | |
* @return self | |
*/ | |
public function setAccessToken(AccessTokenEntity $accessTokenEntity) | |
{ | |
$this->accessTokenEntity = $accessTokenEntity; | |
return $this; | |
} | |
/** | |
* Return access token | |
* | |
* @return AccessTokenEntity | |
*/ | |
public function getAccessToken() | |
{ | |
if (! $this->accessTokenEntity instanceof AccessTokenEntity) { | |
$this->accessTokenEntity = $this->server->getAccessTokenStorage()->get($this->accessTokenId); | |
} | |
return $this->accessTokenEntity; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function save() | |
{ | |
$this->server->getRefreshTokenStorage()->create( | |
$this->getId(), | |
$this->getExpireTime(), | |
$this->getAccessToken()->getId() | |
); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function expire() | |
{ | |
$this->server->getRefreshTokenStorage()->delete($this); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
ScopeEntity | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ 4 | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
__construct(AbstractServer $server) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getId() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getDescription() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
jsonSerialize() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
<?php | |
/** | |
* OAuth 2.0 scope entity | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Entity; | |
use League\OAuth2\Server\AbstractServer; | |
/** | |
* Scope entity class | |
*/ | |
class ScopeEntity implements \JsonSerializable | |
{ | |
use EntityTrait; | |
/** | |
* Scope identifier | |
* | |
* @var string | |
*/ | |
protected $id; | |
/** | |
* Scope description | |
* | |
* @var string | |
*/ | |
protected $description; | |
/** | |
* Authorization or resource server | |
* | |
* @var \League\OAuth2\Server\AbstractServer | |
*/ | |
protected $server; | |
/** | |
* __construct | |
* | |
* @param \League\OAuth2\Server\AbstractServer $server | |
* | |
* @return self | |
*/ | |
public function __construct(AbstractServer $server) | |
{ | |
$this->server = $server; | |
return $this; | |
} | |
/** | |
* Return the scope identifer | |
* | |
* @return string | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Return the scope's description | |
* | |
* @return string | |
*/ | |
public function getDescription() | |
{ | |
return $this->description; | |
} | |
/** | |
* Returns a JSON object when entity is passed into json_encode | |
* | |
* @return array | |
*/ | |
public function jsonSerialize() | |
{ | |
return [ | |
'id' => $this->getId(), | |
'description' => $this->getDescription() | |
]; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 15 / 15 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 53 / 53 |
+
SessionEntity | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 15 / 15 |
+ 23 | +
+
+
+ |
+ 100.00% |
+ 53 / 53 |
+
__construct(AbstractServer $server) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
setId($id) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getId() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
associateScope(ScopeEntity $scope) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ |||
hasScope($scope) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ |||
getScopes() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ |||
formatScopes($unformatted = []) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 4 | +
+
+
+ |
+ 100.00% |
+ 9 / 9 |
+ |||
associateAccessToken(AccessTokenEntity $accessToken) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
associateRefreshToken(RefreshTokenEntity $refreshToken) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
associateClient(ClientEntity $client) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getClient() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ |||
setOwner($type, $id) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ |||
getOwnerId() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getOwnerType() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
save() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 11 / 11 |
+
<?php | |
/** | |
* OAuth 2.0 session entity | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Entity; | |
use League\OAuth2\Server\AbstractServer; | |
use League\OAuth2\Server\Event\SessionOwnerEvent; | |
/** | |
* Session entity grant | |
*/ | |
class SessionEntity | |
{ | |
/** | |
* Session identifier | |
* | |
* @var string | |
*/ | |
protected $id; | |
/** | |
* Client identifier | |
* | |
* @var \League\OAuth2\Server\Entity\ClientEntity | |
*/ | |
protected $client; | |
/** | |
* Session owner identifier | |
* | |
* @var string | |
*/ | |
protected $ownerId; | |
/** | |
* Session owner type (e.g. "user") | |
* | |
* @var string | |
*/ | |
protected $ownerType; | |
/** | |
* Auth code | |
* | |
* @var \League\OAuth2\Server\Entity\AuthCodeEntity | |
*/ | |
protected $authCode; | |
/** | |
* Access token | |
* | |
* @var \League\OAuth2\Server\Entity\AccessTokenEntity | |
*/ | |
protected $accessToken; | |
/** | |
* Refresh token | |
* | |
* @var \League\OAuth2\Server\Entity\RefreshTokenEntity | |
*/ | |
protected $refreshToken; | |
/** | |
* Session scopes | |
* | |
* @var \Symfony\Component\HttpFoundation\ParameterBag | |
*/ | |
protected $scopes; | |
/** | |
* Authorization or resource server | |
* | |
* @var \League\OAuth2\Server\AuthorizationServer|\League\OAuth2\Server\ResourceServer | |
*/ | |
protected $server; | |
/** | |
* __construct | |
* | |
* @param \League\OAuth2\Server\AbstractServer $server | |
* | |
* @return self | |
*/ | |
public function __construct(AbstractServer $server) | |
{ | |
$this->server = $server; | |
return $this; | |
} | |
/** | |
* Set the session identifier | |
* | |
* @param string $id | |
* | |
* @return self | |
*/ | |
public function setId($id) | |
{ | |
$this->id = $id; | |
return $this; | |
} | |
/** | |
* Return the session identifier | |
* | |
* @return string | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Associate a scope | |
* | |
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope | |
* | |
* @return self | |
*/ | |
public function associateScope(ScopeEntity $scope) | |
{ | |
if (!isset($this->scopes[$scope->getId()])) { | |
$this->scopes[$scope->getId()] = $scope; | |
} | |
return $this; | |
} | |
/** | |
* Check if access token has an associated scope | |
* | |
* @param string $scope Scope to check | |
* | |
* @return bool | |
*/ | |
public function hasScope($scope) | |
{ | |
if ($this->scopes === null) { | |
$this->getScopes(); | |
} | |
return isset($this->scopes[$scope]); | |
} | |
/** | |
* Return all scopes associated with the session | |
* | |
* @return \League\OAuth2\Server\Entity\ScopeEntity[] | |
*/ | |
public function getScopes() | |
{ | |
if ($this->scopes === null) { | |
$this->scopes = $this->formatScopes($this->server->getSessionStorage()->getScopes($this)); | |
} | |
return $this->scopes; | |
} | |
/** | |
* Format the local scopes array | |
* | |
* @param \League\OAuth2\Server\Entity\Scope[] | |
* | |
* @return array | |
*/ | |
private function formatScopes($unformatted = []) | |
{ | |
$scopes = []; | |
if (is_array($unformatted)) { | |
foreach ($unformatted as $scope) { | |
if ($scope instanceof ScopeEntity) { | |
$scopes[$scope->getId()] = $scope; | |
} | |
} | |
} | |
return $scopes; | |
} | |
/** | |
* Associate an access token with the session | |
* | |
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken | |
* | |
* @return self | |
*/ | |
public function associateAccessToken(AccessTokenEntity $accessToken) | |
{ | |
$this->accessToken = $accessToken; | |
return $this; | |
} | |
/** | |
* Associate a refresh token with the session | |
* | |
* @param \League\OAuth2\Server\Entity\RefreshTokenEntity $refreshToken | |
* | |
* @return self | |
*/ | |
public function associateRefreshToken(RefreshTokenEntity $refreshToken) | |
{ | |
$this->refreshToken = $refreshToken; | |
return $this; | |
} | |
/** | |
* Associate a client with the session | |
* | |
* @param \League\OAuth2\Server\Entity\ClientEntity $client The client | |
* | |
* @return self | |
*/ | |
public function associateClient(ClientEntity $client) | |
{ | |
$this->client = $client; | |
return $this; | |
} | |
/** | |
* Return the session client | |
* | |
* @return \League\OAuth2\Server\Entity\ClientEntity | |
*/ | |
public function getClient() | |
{ | |
if ($this->client instanceof ClientEntity) { | |
return $this->client; | |
} | |
$this->client = $this->server->getClientStorage()->getBySession($this); | |
return $this->client; | |
} | |
/** | |
* Set the session owner | |
* | |
* @param string $type The type of the owner (e.g. user, app) | |
* @param string $id The identifier of the owner | |
* | |
* @return self | |
*/ | |
public function setOwner($type, $id) | |
{ | |
$this->ownerType = $type; | |
$this->ownerId = $id; | |
$this->server->getEventEmitter()->emit(new SessionOwnerEvent($this)); | |
return $this; | |
} | |
/** | |
* Return session owner identifier | |
* | |
* @return string | |
*/ | |
public function getOwnerId() | |
{ | |
return $this->ownerId; | |
} | |
/** | |
* Return session owner type | |
* | |
* @return string | |
*/ | |
public function getOwnerType() | |
{ | |
return $this->ownerType; | |
} | |
/** | |
* Save the session | |
* | |
* @return void | |
*/ | |
public function save() | |
{ | |
// Save the session and get an identifier | |
$id = $this->server->getSessionStorage()->create( | |
$this->getOwnerType(), | |
$this->getOwnerId(), | |
$this->getClient()->getId(), | |
$this->getClient()->getRedirectUri() | |
); | |
$this->setId($id); | |
// Associate the scope with the session | |
foreach ($this->getScopes() as $scope) { | |
$this->server->getSessionStorage()->associateScope($this, $scope); | |
} | |
} | |
} |
Class | +Coverage | +
---|---|
AccessTokenEntity | 84% |
Class | +CRAP | +
---|---|
AccessTokenEntity | 9 |
Method | +Coverage | +
---|---|
hasScope | 0% |
formatScopes | 88% |
Method | +CRAP | +
---|---|
hasScope | 6 |
formatScopes | 4 |
+ | Code Coverage |
+ ||||||||
+ | Lines |
+ Functions and Methods |
+ Classes and Traits |
+ ||||||
Total | +
+
+
+ |
+ 97.08% |
+ 166 / 171 |
+
+
+
+ |
+ 96.15% |
+ 50 / 52 |
+
+
+
+ |
+ 75.00% |
+ 6 / 8 |
+
AbstractTokenEntity.php | +
+
+
+ |
+ 96.30% |
+ 26 / 27 |
+
+
+
+ |
+ 90.00% |
+ 9 / 10 |
+
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
AccessTokenEntity.php | +
+
+
+ |
+ 84.00% |
+ 21 / 25 |
+
+
+
+ |
+ 80.00% |
+ 4 / 5 |
+
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
AuthCodeEntity.php | +
+
+
+ |
+ 100.00% |
+ 31 / 31 |
+
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
ClientEntity.php | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
EntityTrait.php | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
RefreshTokenEntity.php | +
+
+
+ |
+ 100.00% |
+ 16 / 16 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
ScopeEntity.php | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
SessionEntity.php | +
+
+
+ |
+ 100.00% |
+ 53 / 53 |
+
+
+
+ |
+ 100.00% |
+ 15 / 15 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
+
+ |
+ 66.67% |
+ 2 / 3 |
+ CRAP | +
+
+
+ |
+ 75.00% |
+ 3 / 4 |
+
ClientAuthenticationFailedEvent | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
+
+ |
+ 66.67% |
+ 2 / 3 |
+ 3.14 | +
+
+
+ |
+ 75.00% |
+ 3 / 4 |
+
__construct(Request $request) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getName() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getRequest() | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+ 2 | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
<?php | |
/** | |
* OAuth 2.0 client authentication failed event | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Event; | |
use League\Event\AbstractEvent; | |
use Symfony\Component\HttpFoundation\Request; | |
class ClientAuthenticationFailedEvent extends AbstractEvent | |
{ | |
/** | |
* Request | |
* | |
* @var \Symfony\Component\HttpFoundation\Request | |
*/ | |
private $request; | |
/** | |
* Init the event with a request | |
* | |
* @param \Symfony\Component\HttpFoundation\Request $request | |
*/ | |
public function __construct(Request $request) | |
{ | |
$this->request = $request; | |
} | |
/** | |
* The name of the event | |
* | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return 'error.auth.client'; | |
} | |
/** | |
* Return request | |
* | |
* @return \Symfony\Component\HttpFoundation\Request | |
*/ | |
public function getRequest() | |
{ | |
return $this->request; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+
SessionOwnerEvent | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ 3 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+
__construct(SessionEntity $session) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getName() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getSession() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
<?php | |
/** | |
* OAuth 2.0 session owner event | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Event; | |
use League\Event\AbstractEvent; | |
use League\OAuth2\Server\Entity\SessionEntity; | |
class SessionOwnerEvent extends AbstractEvent | |
{ | |
/** | |
* Session entity | |
* | |
* @var \League\OAuth2\Server\Entity\SessionEntity | |
*/ | |
private $session; | |
/** | |
* Init the event with a session | |
* | |
* @param \League\OAuth2\Server\Entity\SessionEntity $session | |
*/ | |
public function __construct(SessionEntity $session) | |
{ | |
$this->session = $session; | |
} | |
/** | |
* The name of the event | |
* | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return 'session.owner'; | |
} | |
/** | |
* Return session | |
* | |
* @return \League\OAuth2\Server\Entity\SessionEntity | |
*/ | |
public function getSession() | |
{ | |
return $this->session; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
+
+ |
+ 66.67% |
+ 2 / 3 |
+ CRAP | +
+
+
+ |
+ 75.00% |
+ 3 / 4 |
+
UserAuthenticationFailedEvent | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
+
+ |
+ 66.67% |
+ 2 / 3 |
+ 3.14 | +
+
+
+ |
+ 75.00% |
+ 3 / 4 |
+
__construct(Request $request) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getName() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getRequest() | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+ 2 | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
<?php | |
/** | |
* OAuth 2.0 user authentication failed event | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Event; | |
use League\Event\AbstractEvent; | |
use Symfony\Component\HttpFoundation\Request; | |
class UserAuthenticationFailedEvent extends AbstractEvent | |
{ | |
/** | |
* Request | |
* | |
* @var \Symfony\Component\HttpFoundation\Request | |
*/ | |
private $request; | |
/** | |
* Init the event with a request | |
* | |
* @param \Symfony\Component\HttpFoundation\Request $request | |
*/ | |
public function __construct(Request $request) | |
{ | |
$this->request = $request; | |
} | |
/** | |
* The name of the event | |
* | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return 'error.auth.user'; | |
} | |
/** | |
* Return request | |
* | |
* @return \Symfony\Component\HttpFoundation\Request | |
*/ | |
public function getRequest() | |
{ | |
return $this->request; | |
} | |
} |
Class | +Coverage | +
---|---|
UserAuthenticationFailedEvent | 75% |
ClientAuthenticationFailedEvent | 75% |
Class | +CRAP | +
---|
Method | +Coverage | +
---|---|
getRequest | 0% |
getRequest | 0% |
Method | +CRAP | +
---|
+ | Code Coverage |
+ ||||||||
+ | Lines |
+ Functions and Methods |
+ Classes and Traits |
+ ||||||
Total | +
+
+
+ |
+ 83.33% |
+ 10 / 12 |
+
+
+
+ |
+ 77.78% |
+ 7 / 9 |
+
+
+
+ |
+ 33.33% |
+ 1 / 3 |
+
ClientAuthenticationFailedEvent.php | +
+
+
+ |
+ 75.00% |
+ 3 / 4 |
+
+
+
+ |
+ 66.67% |
+ 2 / 3 |
+
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
SessionOwnerEvent.php | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
UserAuthenticationFailedEvent.php | +
+
+
+ |
+ 75.00% |
+ 3 / 4 |
+
+
+
+ |
+ 66.67% |
+ 2 / 3 |
+
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
AccessDeniedException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
__construct() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
<?php | |
/** | |
* OAuth 2.0 Access Denied Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
/** | |
* Exception class | |
*/ | |
class AccessDeniedException extends OAuthException | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public $httpStatusCode = 401; | |
/** | |
* {@inheritdoc} | |
*/ | |
public $errorType = 'access_denied'; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct() | |
{ | |
parent::__construct('The resource owner or authorization server denied the request.'); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
InvalidClientException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
__construct() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
<?php | |
/** | |
* OAuth 2.0 Invalid Client Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
/** | |
* Exception class | |
*/ | |
class InvalidClientException extends OAuthException | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public $httpStatusCode = 401; | |
/** | |
* {@inheritdoc} | |
*/ | |
public $errorType = 'invalid_client'; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct() | |
{ | |
parent::__construct('Client authentication failed.'); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
InvalidCredentialsException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
__construct() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
<?php | |
/** | |
* OAuth 2.0 Invalid Credentials Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
/** | |
* Exception class | |
*/ | |
class InvalidCredentialsException extends OAuthException | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public $httpStatusCode = 401; | |
/** | |
* {@inheritdoc} | |
*/ | |
public $errorType = 'invalid_credentials'; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct() | |
{ | |
parent::__construct('The user credentials were incorrect.'); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
InvalidGrantException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
__construct($parameter) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
<?php | |
/** | |
* OAuth 2.0 Invalid Grant Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
/** | |
* Exception class | |
*/ | |
class InvalidGrantException extends OAuthException | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public $httpStatusCode = 400; | |
/** | |
* {@inheritdoc} | |
*/ | |
public $errorType = 'invalid_grant'; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct($parameter) | |
{ | |
parent::__construct( | |
sprintf( | |
'The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client. Check the "%s" parameter.', | |
$parameter | |
) | |
); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
InvalidRefreshException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
__construct() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
<?php | |
/** | |
* OAuth 2.0 Invalid Refresh Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
/** | |
* Exception class | |
*/ | |
class InvalidRefreshException extends OAuthException | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public $httpStatusCode = 400; | |
/** | |
* {@inheritdoc} | |
*/ | |
public $errorType = 'invalid_request'; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct() | |
{ | |
parent::__construct('The refresh token is invalid.'); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
InvalidRequestException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
__construct($parameter, $redirectUri = null) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
<?php | |
/** | |
* OAuth 2.0 Invalid Request Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
/** | |
* Exception class | |
*/ | |
class InvalidRequestException extends OAuthException | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public $httpStatusCode = 400; | |
/** | |
* {@inheritdoc} | |
*/ | |
public $errorType = 'invalid_request'; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct($parameter, $redirectUri = null) | |
{ | |
parent::__construct( | |
sprintf( | |
'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "%s" parameter.', | |
$parameter | |
) | |
); | |
$this->redirectUri = $redirectUri; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
InvalidScopeException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
__construct($parameter, $redirectUri = null) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
<?php | |
/** | |
* OAuth 2.0 Invalid Scope Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
/** | |
* Exception class | |
*/ | |
class InvalidScopeException extends OAuthException | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public $httpStatusCode = 400; | |
/** | |
* {@inheritdoc} | |
*/ | |
public $errorType = 'invalid_scope'; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct($parameter, $redirectUri = null) | |
{ | |
parent::__construct( | |
sprintf( | |
'The requested scope is invalid, unknown, or malformed. Check the "%s" scope.', | |
$parameter | |
) | |
); | |
$this->redirectUri = $redirectUri; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 25 / 25 |
+
OAuthException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ 15 | +
+
+
+ |
+ 100.00% |
+ 25 / 25 |
+
__construct($msg = 'An error occured') | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
shouldRedirect() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getRedirectUri() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+ |||
getHttpHeaders() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 11 | +
+
+
+ |
+ 100.00% |
+ 17 / 17 |
+
<?php | |
/** | |
* OAuth 2.0 Base Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
use League\OAuth2\Server\Util\RedirectUri; | |
use Symfony\Component\HttpFoundation\Request; | |
/** | |
* Exception class | |
*/ | |
class OAuthException extends \Exception | |
{ | |
/** | |
* The HTTP status code for this exception that should be sent in the response | |
*/ | |
public $httpStatusCode = 400; | |
/** | |
* Redirect URI if the server should redirect back to the client | |
* | |
* @var string|null | |
*/ | |
public $redirectUri = null; | |
/** | |
* The exception type | |
*/ | |
public $errorType = ''; | |
/** | |
* Throw a new exception | |
* | |
* @param string $msg Exception Message | |
*/ | |
public function __construct($msg = 'An error occured') | |
{ | |
parent::__construct($msg); | |
} | |
/** | |
* Should the server redirect back to the client? | |
* | |
* @return bool | |
*/ | |
public function shouldRedirect() | |
{ | |
return is_null($this->redirectUri) ? false : true; | |
} | |
/** | |
* Return redirect URI if set | |
* | |
* @return string|null | |
*/ | |
public function getRedirectUri() | |
{ | |
return RedirectUri::make( | |
$this->redirectUri, | |
[ | |
'error' => $this->errorType, | |
'message' => $this->getMessage(), | |
] | |
); | |
} | |
/** | |
* Get all headers that have to be send with the error response | |
* | |
* @return array Array with header values | |
*/ | |
public function getHttpHeaders() | |
{ | |
$headers = []; | |
switch ($this->httpStatusCode) { | |
case 401: | |
$headers[] = 'HTTP/1.1 401 Unauthorized'; | |
break; | |
case 500: | |
$headers[] = 'HTTP/1.1 500 Internal Server Error'; | |
break; | |
case 501: | |
$headers[] = 'HTTP/1.1 501 Not Implemented'; | |
break; | |
case 400: | |
default: | |
$headers[] = 'HTTP/1.1 400 Bad Request'; | |
break; | |
} | |
// Add "WWW-Authenticate" header | |
// | |
// RFC 6749, section 5.2.: | |
// "If the client attempted to authenticate via the 'Authorization' | |
// request header field, the authorization server MUST | |
// respond with an HTTP 401 (Unauthorized) status code and | |
// include the "WWW-Authenticate" response header field | |
// matching the authentication scheme used by the client. | |
// @codeCoverageIgnoreStart | |
if ($this->errorType === 'invalid_client') { | |
$authScheme = null; | |
$request = new Request(); | |
if ($request->getUser() !== null) { | |
$authScheme = 'Basic'; | |
} else { | |
$authHeader = $request->headers->get('Authorization'); | |
if ($authHeader !== null) { | |
if (strpos($authHeader, 'Bearer') === 0) { | |
$authScheme = 'Bearer'; | |
} elseif (strpos($authHeader, 'Basic') === 0) { | |
$authScheme = 'Basic'; | |
} | |
} | |
} | |
if ($authScheme !== null) { | |
$headers[] = 'WWW-Authenticate: '.$authScheme.' realm=""'; | |
} | |
} | |
// @codeCoverageIgnoreEnd | |
return $headers; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
ServerErrorException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
__construct($parameter = null) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
<?php | |
/** | |
* OAuth 2.0 Server Error Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
/** | |
* Exception class | |
*/ | |
class ServerErrorException extends OAuthException | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public $httpStatusCode = 500; | |
/** | |
* {@inheritdoc} | |
*/ | |
public $errorType = 'server_error'; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct($parameter = null) | |
{ | |
$parameter = is_null($parameter) ? 'The authorization server encountered an unexpected condition which prevented it from fulfilling the request.' : $parameter; | |
parent::__construct($parameter); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
UnauthorizedClientException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
__construct() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
<?php | |
/** | |
* OAuth 2.0 Unauthorized Client Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
/** | |
* Exception class | |
*/ | |
class UnauthorizedClientException extends OAuthException | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public $httpStatusCode = 400; | |
/** | |
* {@inheritdoc} | |
*/ | |
public $errorType = 'unauthorized_client'; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct() | |
{ | |
parent::__construct('The client is not authorized to request an access token using this method.'); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
UnsupportedGrantTypeException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
__construct($parameter) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
<?php | |
/** | |
* OAuth 2.0 Invalid Request Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
/** | |
* Exception class | |
*/ | |
class UnsupportedGrantTypeException extends OAuthException | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public $httpStatusCode = 400; | |
/** | |
* {@inheritdoc} | |
*/ | |
public $errorType = 'unsupported_grant_type'; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct($parameter) | |
{ | |
parent::__construct( | |
sprintf( | |
'The authorization grant type "%s" is not supported by the authorization server.', | |
$parameter | |
) | |
); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
UnsupportedResponseTypeException | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
__construct($parameter, $redirectUri = null) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
<?php | |
/** | |
* OAuth 2.0 Unsupported Response Type Exception | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Exception; | |
/** | |
* Exception class | |
*/ | |
class UnsupportedResponseTypeException extends OAuthException | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public $httpStatusCode = 400; | |
/** | |
* {@inheritdoc} | |
*/ | |
public $errorType = 'unsupported_response_type'; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct($parameter, $redirectUri = null) | |
{ | |
parent::__construct('The authorization server does not support obtaining an access token using this method.'); | |
$this->redirectUri = $redirectUri; | |
} | |
} |
Class | +Coverage | +
---|
Class | +CRAP | +
---|
Method | +Coverage | +
---|
Method | +CRAP | +
---|
+ | Code Coverage |
+ ||||||||
+ | Lines |
+ Functions and Methods |
+ Classes and Traits |
+ ||||||
Total | +
+
+
+ |
+ 100.00% |
+ 67 / 67 |
+
+
+
+ |
+ 100.00% |
+ 15 / 15 |
+
+
+
+ |
+ 100.00% |
+ 12 / 12 |
+
AccessDeniedException.php | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
InvalidClientException.php | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
InvalidCredentialsException.php | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
InvalidGrantException.php | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
InvalidRefreshException.php | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
InvalidRequestException.php | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
InvalidScopeException.php | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
OAuthException.php | +
+
+
+ |
+ 100.00% |
+ 25 / 25 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
ServerErrorException.php | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
UnauthorizedClientException.php | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
UnsupportedGrantTypeException.php | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
UnsupportedResponseTypeException.php | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 8 / 8 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 48 / 48 |
+
AbstractGrant | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 8 / 8 |
+ 21 | +
+
+
+ |
+ 100.00% |
+ 48 / 48 |
+
getIdentifier() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
setIdentifier($identifier) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getResponseType() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
getAccessTokenTTL() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ |||
setAccessTokenTTL($accessTokenTTL) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
setAuthorizationServer(AuthorizationServer $server) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
validateScopes($scopeParam = '', ClientEntity $client, $redirectUri = null) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 11 | +
+
+
+ |
+ 100.00% |
+ 30 / 30 |
+ |||
formatScopes($unformated = []) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 3 | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
<?php | |
/** | |
* OAuth 2.0 Abstract grant | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Grant; | |
use League\OAuth2\Server\AuthorizationServer; | |
use League\OAuth2\Server\Entity\ClientEntity; | |
use League\OAuth2\Server\Entity\ScopeEntity; | |
use League\OAuth2\Server\Exception; | |
/** | |
* Abstract grant class | |
*/ | |
abstract class AbstractGrant implements GrantTypeInterface | |
{ | |
/** | |
* Grant identifier | |
* | |
* @var string | |
*/ | |
protected $identifier = ''; | |
/** | |
* Response type | |
* | |
* @var string | |
*/ | |
protected $responseType; | |
/** | |
* Callback to authenticate a user's name and password | |
* | |
* @var callable | |
*/ | |
protected $callback; | |
/** | |
* AuthServer instance | |
* | |
* @var \League\OAuth2\Server\AuthorizationServer | |
*/ | |
protected $server; | |
/** | |
* Access token expires in override | |
* | |
* @var int | |
*/ | |
protected $accessTokenTTL; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getIdentifier() | |
{ | |
return $this->identifier; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function setIdentifier($identifier) | |
{ | |
$this->identifier = $identifier; | |
return $this; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getResponseType() | |
{ | |
return $this->responseType; | |
} | |
/** | |
* Get the TTL for an access token | |
* | |
* @return int The TTL | |
*/ | |
public function getAccessTokenTTL() | |
{ | |
if ($this->accessTokenTTL) { | |
return $this->accessTokenTTL; | |
} | |
return $this->server->getAccessTokenTTL(); | |
} | |
/** | |
* Override the default access token expire time | |
* | |
* @param int $accessTokenTTL | |
* | |
* @return self | |
*/ | |
public function setAccessTokenTTL($accessTokenTTL) | |
{ | |
$this->accessTokenTTL = $accessTokenTTL; | |
return $this; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function setAuthorizationServer(AuthorizationServer $server) | |
{ | |
$this->server = $server; | |
return $this; | |
} | |
/** | |
* Given a list of scopes, validate them and return an array of Scope entities | |
* | |
* @param string $scopeParam A string of scopes (e.g. "profile email birthday") | |
* @param \League\OAuth2\Server\Entity\ClientEntity $client Client entity | |
* @param string|null $redirectUri The redirect URI to return the user to | |
* | |
* @return \League\OAuth2\Server\Entity\ScopeEntity[] | |
* | |
* @throws \League\OAuth2\Server\Exception\InvalidScopeException If scope is invalid, or no scopes passed when required | |
* @throws | |
*/ | |
public function validateScopes($scopeParam = '', ClientEntity $client, $redirectUri = null) | |
{ | |
$scopesList = explode($this->server->getScopeDelimiter(), $scopeParam); | |
for ($i = 0; $i < count($scopesList); $i++) { | |
$scopesList[$i] = trim($scopesList[$i]); | |
if ($scopesList[$i] === '') { | |
unset($scopesList[$i]); // Remove any junk scopes | |
} | |
} | |
if ( | |
$this->server->scopeParamRequired() === true | |
&& $this->server->getDefaultScope() === null | |
&& count($scopesList) === 0 | |
) { | |
throw new Exception\InvalidRequestException('scope'); | |
} elseif (count($scopesList) === 0 && $this->server->getDefaultScope() !== null) { | |
if (is_array($this->server->getDefaultScope())) { | |
$scopesList = $this->server->getDefaultScope(); | |
} else { | |
$scopesList = [0 => $this->server->getDefaultScope()]; | |
} | |
} | |
$scopes = []; | |
foreach ($scopesList as $scopeItem) { | |
$scope = $this->server->getScopeStorage()->get( | |
$scopeItem, | |
$this->getIdentifier(), | |
$client->getId() | |
); | |
if (($scope instanceof ScopeEntity) === false) { | |
throw new Exception\InvalidScopeException($scopeItem, $redirectUri); | |
} | |
$scopes[$scope->getId()] = $scope; | |
} | |
return $scopes; | |
} | |
/** | |
* Format the local scopes array | |
* | |
* @param \League\OAuth2\Server\Entity\ScopeEntity[] | |
* | |
* @return array | |
*/ | |
protected function formatScopes($unformated = []) | |
{ | |
$scopes = []; | |
foreach ($unformated as $scope) { | |
if ($scope instanceof ScopeEntity) { | |
$scopes[$scope->getId()] = $scope; | |
} | |
} | |
return $scopes; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 105 / 105 |
+
AuthCodeGrant | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ 25 | +
+
+
+ |
+ 100.00% |
+ 105 / 105 |
+
setAuthTokenTTL($authTokenTTL) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
checkAuthorizeParams() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 8 | +
+
+
+ |
+ 100.00% |
+ 30 / 30 |
+ |||
newAuthorizeRequest($type, $typeId, $authParams = []) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 14 / 14 |
+ |||
completeFlow() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 14 | +
+
+
+ |
+ 100.00% |
+ 59 / 59 |
+
<?php | |
/** | |
* OAuth 2.0 Auth code grant | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Grant; | |
use League\OAuth2\Server\Entity\AccessTokenEntity; | |
use League\OAuth2\Server\Entity\AuthCodeEntity; | |
use League\OAuth2\Server\Entity\ClientEntity; | |
use League\OAuth2\Server\Entity\RefreshTokenEntity; | |
use League\OAuth2\Server\Entity\SessionEntity; | |
use League\OAuth2\Server\Event; | |
use League\OAuth2\Server\Exception; | |
use League\OAuth2\Server\Util\SecureKey; | |
/** | |
* Auth code grant class | |
*/ | |
class AuthCodeGrant extends AbstractGrant | |
{ | |
/** | |
* Grant identifier | |
* | |
* @var string | |
*/ | |
protected $identifier = 'authorization_code'; | |
/** | |
* Response type | |
* | |
* @var string | |
*/ | |
protected $responseType = 'code'; | |
/** | |
* AuthServer instance | |
* | |
* @var \League\OAuth2\Server\AuthorizationServer | |
*/ | |
protected $server = null; | |
/** | |
* Access token expires in override | |
* | |
* @var int | |
*/ | |
protected $accessTokenTTL = null; | |
/** | |
* The TTL of the auth token | |
* | |
* @var integer | |
*/ | |
protected $authTokenTTL = 600; | |
/** | |
* Override the default access token expire time | |
* | |
* @param int $authTokenTTL | |
* | |
* @return void | |
*/ | |
public function setAuthTokenTTL($authTokenTTL) | |
{ | |
$this->authTokenTTL = $authTokenTTL; | |
} | |
/** | |
* Check authorize parameters | |
* | |
* @return array Authorize request parameters | |
* | |
* @throws | |
*/ | |
public function checkAuthorizeParams() | |
{ | |
// Get required params | |
$clientId = $this->server->getRequest()->query->get('client_id', null); | |
if (is_null($clientId)) { | |
throw new Exception\InvalidRequestException('client_id'); | |
} | |
$redirectUri = $this->server->getRequest()->query->get('redirect_uri', null); | |
if (is_null($redirectUri)) { | |
throw new Exception\InvalidRequestException('redirect_uri'); | |
} | |
// Validate client ID and redirect URI | |
$client = $this->server->getClientStorage()->get( | |
$clientId, | |
null, | |
$redirectUri, | |
$this->getIdentifier() | |
); | |
if (($client instanceof ClientEntity) === false) { | |
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest())); | |
throw new Exception\InvalidClientException(); | |
} | |
$state = $this->server->getRequest()->query->get('state', null); | |
if ($this->server->stateParamRequired() === true && is_null($state)) { | |
throw new Exception\InvalidRequestException('state', $redirectUri); | |
} | |
$responseType = $this->server->getRequest()->query->get('response_type', null); | |
if (is_null($responseType)) { | |
throw new Exception\InvalidRequestException('response_type', $redirectUri); | |
} | |
// Ensure response type is one that is recognised | |
if (!in_array($responseType, $this->server->getResponseTypes())) { | |
throw new Exception\UnsupportedResponseTypeException($responseType, $redirectUri); | |
} | |
// Validate any scopes that are in the request | |
$scopeParam = $this->server->getRequest()->query->get('scope', ''); | |
$scopes = $this->validateScopes($scopeParam, $client, $redirectUri); | |
return [ | |
'client' => $client, | |
'redirect_uri' => $redirectUri, | |
'state' => $state, | |
'response_type' => $responseType, | |
'scopes' => $scopes | |
]; | |
} | |
/** | |
* Parse a new authorize request | |
* | |
* @param string $type The session owner's type | |
* @param string $typeId The session owner's ID | |
* @param array $authParams The authorize request $_GET parameters | |
* | |
* @return string An authorisation code | |
*/ | |
public function newAuthorizeRequest($type, $typeId, $authParams = []) | |
{ | |
// Create a new session | |
$session = new SessionEntity($this->server); | |
$session->setOwner($type, $typeId); | |
$session->associateClient($authParams['client']); | |
$session->save(); | |
// Create a new auth code | |
$authCode = new AuthCodeEntity($this->server); | |
$authCode->setId(SecureKey::generate()); | |
$authCode->setRedirectUri($authParams['redirect_uri']); | |
$authCode->setExpireTime(time() + $this->authTokenTTL); | |
foreach ($authParams['scopes'] as $scope) { | |
$authCode->associateScope($scope); | |
} | |
$authCode->setSession($session); | |
$authCode->save(); | |
return $authCode->generateRedirectUri($authParams['state']); | |
} | |
/** | |
* Complete the auth code grant | |
* | |
* @return array | |
* | |
* @throws | |
*/ | |
public function completeFlow() | |
{ | |
// Get the required params | |
$clientId = $this->server->getRequest()->request->get('client_id', $this->server->getRequest()->getUser()); | |
if (is_null($clientId)) { | |
throw new Exception\InvalidRequestException('client_id'); | |
} | |
$clientSecret = $this->server->getRequest()->request->get('client_secret', | |
$this->server->getRequest()->getPassword()); | |
if (is_null($clientSecret)) { | |
throw new Exception\InvalidRequestException('client_secret'); | |
} | |
$redirectUri = $this->server->getRequest()->request->get('redirect_uri', null); | |
if (is_null($redirectUri)) { | |
throw new Exception\InvalidRequestException('redirect_uri'); | |
} | |
// Validate client ID and client secret | |
$client = $this->server->getClientStorage()->get( | |
$clientId, | |
$clientSecret, | |
$redirectUri, | |
$this->getIdentifier() | |
); | |
if (($client instanceof ClientEntity) === false) { | |
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest())); | |
throw new Exception\InvalidClientException(); | |
} | |
// Validate the auth code | |
$authCode = $this->server->getRequest()->request->get('code', null); | |
if (is_null($authCode)) { | |
throw new Exception\InvalidRequestException('code'); | |
} | |
$code = $this->server->getAuthCodeStorage()->get($authCode); | |
if (($code instanceof AuthCodeEntity) === false) { | |
throw new Exception\InvalidRequestException('code'); | |
} | |
// Ensure the auth code hasn't expired | |
if ($code->isExpired() === true) { | |
throw new Exception\InvalidRequestException('code'); | |
} | |
// Check redirect URI presented matches redirect URI originally used in authorize request | |
if ($code->getRedirectUri() !== $redirectUri) { | |
throw new Exception\InvalidRequestException('redirect_uri'); | |
} | |
$session = $code->getSession(); | |
$session->associateClient($client); | |
$authCodeScopes = $code->getScopes(); | |
// Generate the access token | |
$accessToken = new AccessTokenEntity($this->server); | |
$accessToken->setId(SecureKey::generate()); | |
$accessToken->setExpireTime($this->getAccessTokenTTL() + time()); | |
foreach ($authCodeScopes as $authCodeScope) { | |
$session->associateScope($authCodeScope); | |
} | |
foreach ($session->getScopes() as $scope) { | |
$accessToken->associateScope($scope); | |
} | |
$this->server->getTokenType()->setSession($session); | |
$this->server->getTokenType()->setParam('access_token', $accessToken->getId()); | |
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL()); | |
// Associate a refresh token if set | |
if ($this->server->hasGrantType('refresh_token')) { | |
$refreshToken = new RefreshTokenEntity($this->server); | |
$refreshToken->setId(SecureKey::generate()); | |
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time()); | |
$this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId()); | |
} | |
// Expire the auth code | |
$code->expire(); | |
// Save all the things | |
$session->save(); | |
$accessToken->setSession($session); | |
$accessToken->save(); | |
if (isset($refreshToken) && $this->server->hasGrantType('refresh_token')) { | |
$refreshToken->setAccessToken($accessToken); | |
$refreshToken->save(); | |
} | |
return $this->server->getTokenType()->generateResponse(); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 37 / 37 |
+
ClientCredentialsGrant | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 6 | +
+
+
+ |
+ 100.00% |
+ 37 / 37 |
+
completeFlow() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 6 | +
+
+
+ |
+ 100.00% |
+ 37 / 37 |
+
<?php | |
/** | |
* OAuth 2.0 Client credentials grant | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Grant; | |
use League\OAuth2\Server\Entity\AccessTokenEntity; | |
use League\OAuth2\Server\Entity\ClientEntity; | |
use League\OAuth2\Server\Entity\SessionEntity; | |
use League\OAuth2\Server\Event; | |
use League\OAuth2\Server\Exception; | |
use League\OAuth2\Server\Util\SecureKey; | |
/** | |
* Client credentials grant class | |
*/ | |
class ClientCredentialsGrant extends AbstractGrant | |
{ | |
/** | |
* Grant identifier | |
* | |
* @var string | |
*/ | |
protected $identifier = 'client_credentials'; | |
/** | |
* Response type | |
* | |
* @var string | |
*/ | |
protected $responseType = null; | |
/** | |
* AuthServer instance | |
* | |
* @var \League\OAuth2\Server\AuthorizationServer | |
*/ | |
protected $server = null; | |
/** | |
* Access token expires in override | |
* | |
* @var int | |
*/ | |
protected $accessTokenTTL = null; | |
/** | |
* Complete the client credentials grant | |
* | |
* @return array | |
* | |
* @throws | |
*/ | |
public function completeFlow() | |
{ | |
// Get the required params | |
$clientId = $this->server->getRequest()->request->get('client_id', $this->server->getRequest()->getUser()); | |
if (is_null($clientId)) { | |
throw new Exception\InvalidRequestException('client_id'); | |
} | |
$clientSecret = $this->server->getRequest()->request->get('client_secret', | |
$this->server->getRequest()->getPassword()); | |
if (is_null($clientSecret)) { | |
throw new Exception\InvalidRequestException('client_secret'); | |
} | |
// Validate client ID and client secret | |
$client = $this->server->getClientStorage()->get( | |
$clientId, | |
$clientSecret, | |
null, | |
$this->getIdentifier() | |
); | |
if (($client instanceof ClientEntity) === false) { | |
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest())); | |
throw new Exception\InvalidClientException(); | |
} | |
// Validate any scopes that are in the request | |
$scopeParam = $this->server->getRequest()->request->get('scope', ''); | |
$scopes = $this->validateScopes($scopeParam, $client); | |
// Create a new session | |
$session = new SessionEntity($this->server); | |
$session->setOwner('client', $client->getId()); | |
$session->associateClient($client); | |
// Generate an access token | |
$accessToken = new AccessTokenEntity($this->server); | |
$accessToken->setId(SecureKey::generate()); | |
$accessToken->setExpireTime($this->getAccessTokenTTL() + time()); | |
// Associate scopes with the session and access token | |
foreach ($scopes as $scope) { | |
$session->associateScope($scope); | |
} | |
foreach ($session->getScopes() as $scope) { | |
$accessToken->associateScope($scope); | |
} | |
// Save everything | |
$session->save(); | |
$accessToken->setSession($session); | |
$accessToken->save(); | |
$this->server->getTokenType()->setSession($session); | |
$this->server->getTokenType()->setParam('access_token', $accessToken->getId()); | |
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL()); | |
return $this->server->getTokenType()->generateResponse(); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | ++ | + | + | + | CRAP | ++ | + |
<?php | |
/** | |
* OAuth 2.0 Grant type interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Grant; | |
use League\OAuth2\Server\AuthorizationServer; | |
/** | |
* Grant type interface | |
*/ | |
interface GrantTypeInterface | |
{ | |
/** | |
* Return the identifier | |
* | |
* @return string | |
*/ | |
public function getIdentifier(); | |
/** | |
* Return the identifier | |
* | |
* @param string $identifier | |
* | |
* @return self | |
*/ | |
public function setIdentifier($identifier); | |
/** | |
* Return the response type | |
* | |
* @return string | |
*/ | |
public function getResponseType(); | |
/** | |
* Inject the authorization server into the grant | |
* | |
* @param \League\OAuth2\Server\AuthorizationServer $server The authorization server instance | |
* | |
* @return self | |
*/ | |
public function setAuthorizationServer(AuthorizationServer $server); | |
/** | |
* Complete the grant flow | |
* | |
* @return array | |
*/ | |
public function completeFlow(); | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 62 / 62 |
+
PasswordGrant | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ 15 | +
+
+
+ |
+ 100.00% |
+ 62 / 62 |
+
setVerifyCredentialsCallback(callable $callback) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getVerifyCredentialsCallback() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 3 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ |||
completeFlow() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 11 | +
+
+
+ |
+ 100.00% |
+ 57 / 57 |
+
<?php | |
/** | |
* OAuth 2.0 Password grant | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Grant; | |
use League\OAuth2\Server\Entity\AccessTokenEntity; | |
use League\OAuth2\Server\Entity\ClientEntity; | |
use League\OAuth2\Server\Entity\RefreshTokenEntity; | |
use League\OAuth2\Server\Entity\SessionEntity; | |
use League\OAuth2\Server\Event; | |
use League\OAuth2\Server\Exception; | |
use League\OAuth2\Server\Util\SecureKey; | |
/** | |
* Password grant class | |
*/ | |
class PasswordGrant extends AbstractGrant | |
{ | |
/** | |
* Grant identifier | |
* | |
* @var string | |
*/ | |
protected $identifier = 'password'; | |
/** | |
* Response type | |
* | |
* @var string | |
*/ | |
protected $responseType; | |
/** | |
* Callback to authenticate a user's name and password | |
* | |
* @var callable | |
*/ | |
protected $callback; | |
/** | |
* Access token expires in override | |
* | |
* @var int | |
*/ | |
protected $accessTokenTTL; | |
/** | |
* Set the callback to verify a user's username and password | |
* | |
* @param callable $callback The callback function | |
* | |
* @return void | |
*/ | |
public function setVerifyCredentialsCallback(callable $callback) | |
{ | |
$this->callback = $callback; | |
} | |
/** | |
* Return the callback function | |
* | |
* @return callable | |
* | |
* @throws | |
*/ | |
protected function getVerifyCredentialsCallback() | |
{ | |
if (is_null($this->callback) || !is_callable($this->callback)) { | |
throw new Exception\ServerErrorException('Null or non-callable callback set on Password grant'); | |
} | |
return $this->callback; | |
} | |
/** | |
* Complete the password grant | |
* | |
* @return array | |
* | |
* @throws | |
*/ | |
public function completeFlow() | |
{ | |
// Get the required params | |
$clientId = $this->server->getRequest()->request->get('client_id', $this->server->getRequest()->getUser()); | |
if (is_null($clientId)) { | |
throw new Exception\InvalidRequestException('client_id'); | |
} | |
$clientSecret = $this->server->getRequest()->request->get('client_secret', | |
$this->server->getRequest()->getPassword()); | |
if (is_null($clientSecret)) { | |
throw new Exception\InvalidRequestException('client_secret'); | |
} | |
// Validate client ID and client secret | |
$client = $this->server->getClientStorage()->get( | |
$clientId, | |
$clientSecret, | |
null, | |
$this->getIdentifier() | |
); | |
if (($client instanceof ClientEntity) === false) { | |
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest())); | |
throw new Exception\InvalidClientException(); | |
} | |
$username = $this->server->getRequest()->request->get('username', null); | |
if (is_null($username)) { | |
throw new Exception\InvalidRequestException('username'); | |
} | |
$password = $this->server->getRequest()->request->get('password', null); | |
if (is_null($password)) { | |
throw new Exception\InvalidRequestException('password'); | |
} | |
// Check if user's username and password are correct | |
$userId = call_user_func($this->getVerifyCredentialsCallback(), $username, $password); | |
if ($userId === false) { | |
$this->server->getEventEmitter()->emit(new Event\UserAuthenticationFailedEvent($this->server->getRequest())); | |
throw new Exception\InvalidCredentialsException(); | |
} | |
// Validate any scopes that are in the request | |
$scopeParam = $this->server->getRequest()->request->get('scope', ''); | |
$scopes = $this->validateScopes($scopeParam, $client); | |
// Create a new session | |
$session = new SessionEntity($this->server); | |
$session->setOwner('user', $userId); | |
$session->associateClient($client); | |
// Generate an access token | |
$accessToken = new AccessTokenEntity($this->server); | |
$accessToken->setId(SecureKey::generate()); | |
$accessToken->setExpireTime($this->getAccessTokenTTL() + time()); | |
// Associate scopes with the session and access token | |
foreach ($scopes as $scope) { | |
$session->associateScope($scope); | |
} | |
foreach ($session->getScopes() as $scope) { | |
$accessToken->associateScope($scope); | |
} | |
$this->server->getTokenType()->setSession($session); | |
$this->server->getTokenType()->setParam('access_token', $accessToken->getId()); | |
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL()); | |
// Associate a refresh token if set | |
if ($this->server->hasGrantType('refresh_token')) { | |
$refreshToken = new RefreshTokenEntity($this->server); | |
$refreshToken->setId(SecureKey::generate()); | |
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time()); | |
$this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId()); | |
} | |
// Save everything | |
$session->save(); | |
$accessToken->setSession($session); | |
$accessToken->save(); | |
if ($this->server->hasGrantType('refresh_token')) { | |
$refreshToken->setAccessToken($accessToken); | |
$refreshToken->save(); | |
} | |
return $this->server->getTokenType()->generateResponse(); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 60 / 60 |
+
RefreshTokenGrant | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ 13 | +
+
+
+ |
+ 100.00% |
+ 60 / 60 |
+
setRefreshTokenTTL($refreshTokenTTL) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getRefreshTokenTTL() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
completeFlow() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 11 | +
+
+
+ |
+ 100.00% |
+ 57 / 57 |
+
<?php | |
/** | |
* OAuth 2.0 Refresh token grant | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Grant; | |
use League\OAuth2\Server\Entity\AccessTokenEntity; | |
use League\OAuth2\Server\Entity\ClientEntity; | |
use League\OAuth2\Server\Entity\RefreshTokenEntity; | |
use League\OAuth2\Server\Event; | |
use League\OAuth2\Server\Exception; | |
use League\OAuth2\Server\Util\SecureKey; | |
/** | |
* Referesh token grant | |
*/ | |
class RefreshTokenGrant extends AbstractGrant | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
protected $identifier = 'refresh_token'; | |
/** | |
* Refresh token TTL (default = 604800 | 1 week) | |
* | |
* @var integer | |
*/ | |
protected $refreshTokenTTL = 604800; | |
/** | |
* Set the TTL of the refresh token | |
* | |
* @param int $refreshTokenTTL | |
* | |
* @return void | |
*/ | |
public function setRefreshTokenTTL($refreshTokenTTL) | |
{ | |
$this->refreshTokenTTL = $refreshTokenTTL; | |
} | |
/** | |
* Get the TTL of the refresh token | |
* | |
* @return int | |
*/ | |
public function getRefreshTokenTTL() | |
{ | |
return $this->refreshTokenTTL; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function completeFlow() | |
{ | |
$clientId = $this->server->getRequest()->request->get('client_id', $this->server->getRequest()->getUser()); | |
if (is_null($clientId)) { | |
throw new Exception\InvalidRequestException('client_id'); | |
} | |
$clientSecret = $this->server->getRequest()->request->get('client_secret', | |
$this->server->getRequest()->getPassword()); | |
if (is_null($clientSecret)) { | |
throw new Exception\InvalidRequestException('client_secret'); | |
} | |
// Validate client ID and client secret | |
$client = $this->server->getClientStorage()->get( | |
$clientId, | |
$clientSecret, | |
null, | |
$this->getIdentifier() | |
); | |
if (($client instanceof ClientEntity) === false) { | |
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest())); | |
throw new Exception\InvalidClientException(); | |
} | |
$oldRefreshTokenParam = $this->server->getRequest()->request->get('refresh_token', null); | |
if ($oldRefreshTokenParam === null) { | |
throw new Exception\InvalidRequestException('refresh_token'); | |
} | |
// Validate refresh token | |
$oldRefreshToken = $this->server->getRefreshTokenStorage()->get($oldRefreshTokenParam); | |
if (($oldRefreshToken instanceof RefreshTokenEntity) === false) { | |
throw new Exception\InvalidRefreshException(); | |
} | |
// Ensure the old refresh token hasn't expired | |
if ($oldRefreshToken->isExpired() === true) { | |
throw new Exception\InvalidRefreshException(); | |
} | |
$oldAccessToken = $oldRefreshToken->getAccessToken(); | |
// Get the scopes for the original session | |
$session = $oldAccessToken->getSession(); | |
$scopes = $this->formatScopes($session->getScopes()); | |
// Get and validate any requested scopes | |
$requestedScopesString = $this->server->getRequest()->request->get('scope', ''); | |
$requestedScopes = $this->validateScopes($requestedScopesString, $client); | |
// If no new scopes are requested then give the access token the original session scopes | |
if (count($requestedScopes) === 0) { | |
$newScopes = $scopes; | |
} else { | |
// The OAuth spec says that a refreshed access token can have the original scopes or fewer so ensure | |
// the request doesn't include any new scopes | |
foreach ($requestedScopes as $requestedScope) { | |
if (!isset($scopes[$requestedScope->getId()])) { | |
throw new Exception\InvalidScopeException($requestedScope->getId()); | |
} | |
} | |
$newScopes = $requestedScopes; | |
} | |
// Generate a new access token and assign it the correct sessions | |
$newAccessToken = new AccessTokenEntity($this->server); | |
$newAccessToken->setId(SecureKey::generate()); | |
$newAccessToken->setExpireTime($this->getAccessTokenTTL() + time()); | |
$newAccessToken->setSession($session); | |
foreach ($newScopes as $newScope) { | |
$newAccessToken->associateScope($newScope); | |
} | |
// Expire the old token and save the new one | |
$oldAccessToken->expire(); | |
$newAccessToken->save(); | |
$this->server->getTokenType()->setSession($session); | |
$this->server->getTokenType()->setParam('access_token', $newAccessToken->getId()); | |
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL()); | |
// Expire the old refresh token | |
$oldRefreshToken->expire(); | |
// Generate a new refresh token | |
$newRefreshToken = new RefreshTokenEntity($this->server); | |
$newRefreshToken->setId(SecureKey::generate()); | |
$newRefreshToken->setExpireTime($this->getRefreshTokenTTL() + time()); | |
$newRefreshToken->setAccessToken($newAccessToken); | |
$newRefreshToken->save(); | |
$this->server->getTokenType()->setParam('refresh_token', $newRefreshToken->getId()); | |
return $this->server->getTokenType()->generateResponse(); | |
} | |
} |
Class | +Coverage | +
---|
Class | +CRAP | +
---|
Method | +Coverage | +
---|
Method | +CRAP | +
---|
+ | Code Coverage |
+ ||||||||
+ | Lines |
+ Functions and Methods |
+ Classes and Traits |
+ ||||||
Total | +
+
+
+ |
+ 100.00% |
+ 312 / 312 |
+
+
+
+ |
+ 100.00% |
+ 19 / 19 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+
AbstractGrant.php | +
+
+
+ |
+ 100.00% |
+ 48 / 48 |
+
+
+
+ |
+ 100.00% |
+ 8 / 8 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
AuthCodeGrant.php | +
+
+
+ |
+ 100.00% |
+ 105 / 105 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
ClientCredentialsGrant.php | +
+
+
+ |
+ 100.00% |
+ 37 / 37 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
GrantTypeInterface.php | ++ | + | + | + | + | + | |||
PasswordGrant.php | +
+
+
+ |
+ 100.00% |
+ 62 / 62 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
RefreshTokenGrant.php | +
+
+
+ |
+ 100.00% |
+ 60 / 60 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 29 / 29 |
+
ResourceServer | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+ 12 | +
+
+
+ |
+ 100.00% |
+ 29 / 29 |
+
__construct( + SessionInterface $sessionStorage, + AccessTokenInterface $accessTokenStorage, + ClientInterface $clientStorage, + ScopeInterface $scopeStorage + ) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+ |||
setIdKey($key) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getAccessToken() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
isValidRequest($headersOnly = true, $accessToken = null) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 4 | +
+
+
+ |
+ 100.00% |
+ 9 / 9 |
+ |||
determineAccessToken($headersOnly = false) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 5 | +
+
+
+ |
+ 100.00% |
+ 10 / 10 |
+
<?php | |
/** | |
* OAuth 2.0 Resource Server | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server; | |
use League\OAuth2\Server\Entity\AccessTokenEntity; | |
use League\OAuth2\Server\Storage\AccessTokenInterface; | |
use League\OAuth2\Server\Storage\ClientInterface; | |
use League\OAuth2\Server\Storage\ScopeInterface; | |
use League\OAuth2\Server\Storage\SessionInterface; | |
use League\OAuth2\Server\TokenType\Bearer; | |
/** | |
* OAuth 2.0 Resource Server | |
*/ | |
class ResourceServer extends AbstractServer | |
{ | |
/** | |
* The access token | |
* | |
* @var \League\OAuth2\Server\Entity\AccessTokenEntity | |
*/ | |
protected $accessToken; | |
/** | |
* The query string key which is used by clients to present the access token (default: access_token) | |
* | |
* @var string | |
*/ | |
protected $tokenKey = 'access_token'; | |
/** | |
* Initialise the resource server | |
* | |
* @param SessionInterface $sessionStorage | |
* @param AccessTokenInterface $accessTokenStorage | |
* @param ClientInterface $clientStorage | |
* @param ScopeInterface $scopeStorage | |
* | |
* @return self | |
*/ | |
public function __construct( | |
SessionInterface $sessionStorage, | |
AccessTokenInterface $accessTokenStorage, | |
ClientInterface $clientStorage, | |
ScopeInterface $scopeStorage | |
) { | |
$this->setSessionStorage($sessionStorage); | |
$this->setAccessTokenStorage($accessTokenStorage); | |
$this->setClientStorage($clientStorage); | |
$this->setScopeStorage($scopeStorage); | |
// Set Bearer as the default token type | |
$this->setTokenType(new Bearer()); | |
parent::__construct(); | |
return $this; | |
} | |
/** | |
* Sets the query string key for the access token. | |
* | |
* @param string $key The new query string key | |
* | |
* @return self | |
*/ | |
public function setIdKey($key) | |
{ | |
$this->tokenKey = $key; | |
return $this; | |
} | |
/** | |
* Gets the access token | |
* | |
* @return \League\OAuth2\Server\Entity\AccessTokenEntity | |
*/ | |
public function getAccessToken() | |
{ | |
return $this->accessToken; | |
} | |
/** | |
* Checks if the access token is valid or not | |
* | |
* @param bool $headersOnly Limit Access Token to Authorization header only | |
* @param AccessTokenEntity|null $accessToken Access Token | |
* | |
* @return bool | |
* | |
* @throws | |
*/ | |
public function isValidRequest($headersOnly = true, $accessToken = null) | |
{ | |
$accessTokenString = ($accessToken !== null) | |
? $accessToken | |
: $this->determineAccessToken($headersOnly); | |
// Set the access token | |
$this->accessToken = $this->getAccessTokenStorage()->get($accessTokenString); | |
// Ensure the access token exists | |
if (!$this->accessToken instanceof AccessTokenEntity) { | |
throw new Exception\AccessDeniedException(); | |
} | |
// Check the access token hasn't expired | |
// Ensure the auth code hasn't expired | |
if ($this->accessToken->isExpired() === true) { | |
throw new Exception\AccessDeniedException(); | |
} | |
return true; | |
} | |
/** | |
* Reads in the access token from the headers | |
* | |
* @param bool $headersOnly Limit Access Token to Authorization header only | |
* | |
* @throws Exception\InvalidRequestException Thrown if there is no access token presented | |
* | |
* @return string | |
*/ | |
public function determineAccessToken($headersOnly = false) | |
{ | |
if ($this->getRequest()->headers->get('Authorization') !== null) { | |
$accessToken = $this->getTokenType()->determineAccessTokenInHeader($this->getRequest()); | |
} elseif ($headersOnly === false) { | |
$accessToken = ($this->getRequest()->server->get('REQUEST_METHOD') === 'GET') | |
? $this->getRequest()->query->get($this->tokenKey) | |
: $this->getRequest()->request->get($this->tokenKey); | |
} | |
if (empty($accessToken)) { | |
throw new Exception\InvalidRequestException('access token'); | |
} | |
return $accessToken; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
AbstractStorage | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
setServer(AbstractServer $server) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getServer() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
<?php | |
/** | |
* OAuth 2.0 abstract storage | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Storage; | |
use League\OAuth2\Server\AbstractServer; | |
/** | |
* Abstract storage class | |
*/ | |
abstract class AbstractStorage implements StorageInterface | |
{ | |
/** | |
* Server | |
* | |
* @var \League\OAuth2\Server\AbstractServer $server | |
*/ | |
protected $server; | |
/** | |
* Set the server | |
* | |
* @param \League\OAuth2\Server\AbstractServer $server | |
* | |
* @return self | |
*/ | |
public function setServer(AbstractServer $server) | |
{ | |
$this->server = $server; | |
return $this; | |
} | |
/** | |
* Return the server | |
* | |
* @return \League\OAuth2\Server\AbstractServer | |
*/ | |
protected function getServer() | |
{ | |
return $this->server; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | ++ | + | + | + | CRAP | ++ | + |
<?php | |
/** | |
* OAuth 2.0 Access token storage interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Storage; | |
use League\OAuth2\Server\Entity\AccessTokenEntity; | |
use League\OAuth2\Server\Entity\ScopeEntity; | |
/** | |
* Access token interface | |
*/ | |
interface AccessTokenInterface extends StorageInterface | |
{ | |
/** | |
* Get an instance of Entity\AccessTokenEntity | |
* | |
* @param string $token The access token | |
* | |
* @return \League\OAuth2\Server\Entity\AccessTokenEntity | |
*/ | |
public function get($token); | |
/** | |
* Get the scopes for an access token | |
* | |
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token | |
* | |
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity | |
*/ | |
public function getScopes(AccessTokenEntity $token); | |
/** | |
* Creates a new access token | |
* | |
* @param string $token The access token | |
* @param integer $expireTime The expire time expressed as a unix timestamp | |
* @param string|integer $sessionId The session ID | |
* | |
* @return void | |
*/ | |
public function create($token, $expireTime, $sessionId); | |
/** | |
* Associate a scope with an acess token | |
* | |
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token | |
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope | |
* | |
* @return void | |
*/ | |
public function associateScope(AccessTokenEntity $token, ScopeEntity $scope); | |
/** | |
* Delete an access token | |
* | |
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token to delete | |
* | |
* @return void | |
*/ | |
public function delete(AccessTokenEntity $token); | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | ++ | + | + | + | CRAP | ++ | + |
<?php | |
/** | |
* OAuth 2.0 Auth code storage interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Storage; | |
use League\OAuth2\Server\Entity\AuthCodeEntity; | |
use League\OAuth2\Server\Entity\ScopeEntity; | |
/** | |
* Auth code storage interface | |
*/ | |
interface AuthCodeInterface extends StorageInterface | |
{ | |
/** | |
* Get the auth code | |
* | |
* @param string $code | |
* | |
* @return \League\OAuth2\Server\Entity\AuthCodeEntity | |
*/ | |
public function get($code); | |
/** | |
* Create an auth code. | |
* | |
* @param string $token The token ID | |
* @param integer $expireTime Token expire time | |
* @param integer $sessionId Session identifier | |
* @param string $redirectUri Client redirect uri | |
* | |
* @return void | |
*/ | |
public function create($token, $expireTime, $sessionId, $redirectUri); | |
/** | |
* Get the scopes for an access token | |
* | |
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The auth code | |
* | |
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity | |
*/ | |
public function getScopes(AuthCodeEntity $token); | |
/** | |
* Associate a scope with an acess token | |
* | |
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The auth code | |
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope | |
* | |
* @return void | |
*/ | |
public function associateScope(AuthCodeEntity $token, ScopeEntity $scope); | |
/** | |
* Delete an access token | |
* | |
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The access token to delete | |
* | |
* @return void | |
*/ | |
public function delete(AuthCodeEntity $token); | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | ++ | + | + | + | CRAP | ++ | + |
<?php | |
/** | |
* OAuth 2.0 Client storage interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Storage; | |
use League\OAuth2\Server\Entity\SessionEntity; | |
/** | |
* Client storage interface | |
*/ | |
interface ClientInterface extends StorageInterface | |
{ | |
/** | |
* Validate a client | |
* | |
* @param string $clientId The client's ID | |
* @param string $clientSecret The client's secret (default = "null") | |
* @param string $redirectUri The client's redirect URI (default = "null") | |
* @param string $grantType The grant type used (default = "null") | |
* | |
* @return \League\OAuth2\Server\Entity\ClientEntity | |
*/ | |
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null); | |
/** | |
* Get the client associated with a session | |
* | |
* @param \League\OAuth2\Server\Entity\SessionEntity $session The session | |
* | |
* @return \League\OAuth2\Server\Entity\ClientEntity | |
*/ | |
public function getBySession(SessionEntity $session); | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | ++ | + | + | + | CRAP | ++ | + |
<?php | |
/** | |
* OAuth 2.0 Refresh token storage interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Storage; | |
use League\OAuth2\Server\Entity\RefreshTokenEntity; | |
/** | |
* Refresh token interface | |
*/ | |
interface RefreshTokenInterface extends StorageInterface | |
{ | |
/** | |
* Return a new instance of \League\OAuth2\Server\Entity\RefreshTokenEntity | |
* | |
* @param string $token | |
* | |
* @return \League\OAuth2\Server\Entity\RefreshTokenEntity | |
*/ | |
public function get($token); | |
/** | |
* Create a new refresh token_name | |
* | |
* @param string $token | |
* @param integer $expireTime | |
* @param string $accessToken | |
* | |
* @return \League\OAuth2\Server\Entity\RefreshTokenEntity | |
*/ | |
public function create($token, $expireTime, $accessToken); | |
/** | |
* Delete the refresh token | |
* | |
* @param \League\OAuth2\Server\Entity\RefreshTokenEntity $token | |
* | |
* @return void | |
*/ | |
public function delete(RefreshTokenEntity $token); | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | ++ | + | + | + | CRAP | ++ | + |
<?php | |
/** | |
* OAuth 2.0 Scope storage interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Storage; | |
/** | |
* Scope interface | |
*/ | |
interface ScopeInterface extends StorageInterface | |
{ | |
/** | |
* Return information about a scope | |
* | |
* @param string $scope The scope | |
* @param string $grantType The grant type used in the request (default = "null") | |
* @param string $clientId The client sending the request (default = "null") | |
* | |
* @return \League\OAuth2\Server\Entity\ScopeEntity | |
*/ | |
public function get($scope, $grantType = null, $clientId = null); | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | ++ | + | + | + | CRAP | ++ | + |
<?php | |
/** | |
* OAuth 2.0 Session storage interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Storage; | |
use League\OAuth2\Server\Entity\AccessTokenEntity; | |
use League\OAuth2\Server\Entity\AuthCodeEntity; | |
use League\OAuth2\Server\Entity\ScopeEntity; | |
use League\OAuth2\Server\Entity\SessionEntity; | |
/** | |
* Session storage interface | |
*/ | |
interface SessionInterface extends StorageInterface | |
{ | |
/** | |
* Get a session from an access token | |
* | |
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken The access token | |
* | |
* @return \League\OAuth2\Server\Entity\SessionEntity | |
*/ | |
public function getByAccessToken(AccessTokenEntity $accessToken); | |
/** | |
* Get a session from an auth code | |
* | |
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $authCode The auth code | |
* | |
* @return \League\OAuth2\Server\Entity\SessionEntity | |
*/ | |
public function getByAuthCode(AuthCodeEntity $authCode); | |
/** | |
* Get a session's scopes | |
* | |
* @param \League\OAuth2\Server\Entity\SessionEntity | |
* | |
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity | |
*/ | |
public function getScopes(SessionEntity $session); | |
/** | |
* Create a new session | |
* | |
* @param string $ownerType Session owner's type (user, client) | |
* @param string $ownerId Session owner's ID | |
* @param string $clientId Client ID | |
* @param string $clientRedirectUri Client redirect URI (default = null) | |
* | |
* @return integer The session's ID | |
*/ | |
public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = null); | |
/** | |
* Associate a scope with a session | |
* | |
* @param \League\OAuth2\Server\Entity\SessionEntity $session The session | |
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope | |
* | |
* @return void | |
*/ | |
public function associateScope(SessionEntity $session, ScopeEntity $scope); | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | ++ | + | + | + | CRAP | ++ | + |
<?php | |
/** | |
* OAuth 2.0 Storage interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Storage; | |
use League\OAuth2\Server\AbstractServer; | |
/** | |
* Storage interface | |
*/ | |
interface StorageInterface | |
{ | |
/** | |
* Set the server | |
* | |
* @param \League\OAuth2\Server\AbstractServer $server | |
*/ | |
public function setServer(AbstractServer $server); | |
} |
Class | +Coverage | +
---|
Class | +CRAP | +
---|
Method | +Coverage | +
---|
Method | +CRAP | +
---|
+ | Code Coverage |
+ ||||||||
+ | Lines |
+ Functions and Methods |
+ Classes and Traits |
+ ||||||
Total | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
AbstractStorage.php | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
AccessTokenInterface.php | ++ | + | + | + | + | + | |||
AuthCodeInterface.php | ++ | + | + | + | + | + | |||
ClientInterface.php | ++ | + | + | + | + | + | |||
RefreshTokenInterface.php | ++ | + | + | + | + | + | |||
ScopeInterface.php | ++ | + | + | + | + | + | |||
SessionInterface.php | ++ | + | + | + | + | + | |||
StorageInterface.php | ++ | + | + | + | + | + |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
AbstractTokenType | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+ 5 | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
setServer(AbstractServer $server) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
setSession(SessionEntity $session) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
setParam($key, $value) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getParam($key) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
<?php | |
/** | |
* OAuth 2.0 Abstract Token Type | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\TokenType; | |
use League\OAuth2\Server\AbstractServer; | |
use League\OAuth2\Server\Entity\SessionEntity; | |
abstract class AbstractTokenType | |
{ | |
/** | |
* Response array | |
* | |
* @var array | |
*/ | |
protected $response = []; | |
/** | |
* Server | |
* | |
* @var \League\OAuth2\Server\AbstractServer $server | |
*/ | |
protected $server; | |
/** | |
* Server | |
* | |
* @var \League\OAuth2\Server\Entity\SessionEntity $session | |
*/ | |
protected $session; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function setServer(AbstractServer $server) | |
{ | |
$this->server = $server; | |
return $this; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function setSession(SessionEntity $session) | |
{ | |
$this->session = $session; | |
return $this; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function setParam($key, $value) | |
{ | |
$this->response[$key] = $value; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getParam($key) | |
{ | |
return isset($this->response[$key]) ? $this->response[$key] : null; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 11 / 11 |
+
Bearer | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ 4 | +
+
+
+ |
+ 100.00% |
+ 11 / 11 |
+
generateResponse() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 8 / 8 |
+ |||
determineAccessTokenInHeader(Request $request) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
<?php | |
/** | |
* OAuth 2.0 Bearer Token Type | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\TokenType; | |
use Symfony\Component\HttpFoundation\Request; | |
class Bearer extends AbstractTokenType implements TokenTypeInterface | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function generateResponse() | |
{ | |
$return = [ | |
'access_token' => $this->getParam('access_token'), | |
'token_type' => 'Bearer', | |
'expires_in' => $this->getParam('expires_in'), | |
]; | |
if (!is_null($this->getParam('refresh_token'))) { | |
$return['refresh_token'] = $this->getParam('refresh_token'); | |
} | |
return $return; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function determineAccessTokenInHeader(Request $request) | |
{ | |
$header = $request->headers->get('Authorization'); | |
$accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header)); | |
return ($accessToken === 'Bearer') ? '' : $accessToken; | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | ++ | + | + | + | CRAP | ++ | + |
<?php | |
/** | |
* OAuth 2.0 Token Type Interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\TokenType; | |
use League\OAuth2\Server\AbstractServer; | |
use League\OAuth2\Server\Entity\SessionEntity; | |
use Symfony\Component\HttpFoundation\Request; | |
interface TokenTypeInterface | |
{ | |
/** | |
* Generate a response | |
* | |
* @return array | |
*/ | |
public function generateResponse(); | |
/** | |
* Set the server | |
* | |
* @param \League\OAuth2\Server\AbstractServer $server | |
* | |
* @return self | |
*/ | |
public function setServer(AbstractServer $server); | |
/** | |
* Set a key/value response pair | |
* | |
* @param string $key | |
* @param mixed $value | |
*/ | |
public function setParam($key, $value); | |
/** | |
* Get a key from the response array | |
* | |
* @param string $key | |
* | |
* @return mixed | |
*/ | |
public function getParam($key); | |
/** | |
* @param \League\OAuth2\Server\Entity\SessionEntity $session | |
* | |
* @return self | |
*/ | |
public function setSession(SessionEntity $session); | |
/** | |
* Determine the access token in the authorization header | |
* | |
* @param \Symfony\Component\HttpFoundation\Request $request | |
* | |
* @return string | |
*/ | |
public function determineAccessTokenInHeader(Request $request); | |
} |
Class | +Coverage | +
---|
Class | +CRAP | +
---|
Method | +Coverage | +
---|
Method | +CRAP | +
---|
+ | Code Coverage |
+ ||||||||
+ | Lines |
+ Functions and Methods |
+ Classes and Traits |
+ ||||||
Total | +
+
+
+ |
+ 100.00% |
+ 18 / 18 |
+
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
AbstractTokenType.php | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
Bearer.php | +
+
+
+ |
+ 100.00% |
+ 11 / 11 |
+
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
TokenTypeInterface.php | ++ | + | + | + | + | + |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
DefaultAlgorithm | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 4 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
generate($len = 40) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 4 | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
<?php | |
/** | |
* OAuth 2.0 Secure key interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Util\KeyAlgorithm; | |
class DefaultAlgorithm implements KeyAlgorithmInterface | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function generate($len = 40) | |
{ | |
$stripped = ''; | |
do { | |
$bytes = openssl_random_pseudo_bytes($len, $strong); | |
// We want to stop execution if the key fails because, well, that is bad. | |
if ($bytes === false || $strong === false) { | |
// @codeCoverageIgnoreStart | |
throw new \Exception('Error Generating Key'); | |
// @codeCoverageIgnoreEnd | |
} | |
$stripped .= str_replace(['/', '+', '='], '', base64_encode($bytes)); | |
} while (strlen($stripped) < $len); | |
return substr($stripped, 0, $len); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | ++ | + | + | + | CRAP | ++ | + |
<?php | |
/** | |
* OAuth 2.0 Secure key interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Util\KeyAlgorithm; | |
interface KeyAlgorithmInterface | |
{ | |
/** | |
* Generate a new unique code | |
* | |
* @param integer $len Length of the generated code | |
* | |
* @return string | |
*/ | |
public function generate($len); | |
} |
Class | +Coverage | +
---|
Class | +CRAP | +
---|
Method | +Coverage | +
---|
Method | +CRAP | +
---|
+ | Code Coverage |
+ ||||||||
+ | Lines |
+ Functions and Methods |
+ Classes and Traits |
+ ||||||
Total | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
DefaultAlgorithm.php | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
KeyAlgorithmInterface.php | ++ | + | + | + | + | + |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
RedirectUri | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
make($uri, $params = [], $queryDelimeter = '?') | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
<?php | |
/** | |
* OAuth 2.0 Redirect URI generator | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Util; | |
/** | |
* RedirectUri class | |
*/ | |
class RedirectUri | |
{ | |
/** | |
* Generate a new redirect uri | |
* | |
* @param string $uri The base URI | |
* @param array $params The query string parameters | |
* @param string $queryDelimeter The query string delimeter (default: "?") | |
* | |
* @return string The updated URI | |
*/ | |
public static function make($uri, $params = [], $queryDelimeter = '?') | |
{ | |
$uri .= (strstr($uri, $queryDelimeter) === false) ? $queryDelimeter : '&'; | |
return $uri.http_build_query($params); | |
} | |
} |
+ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ CRAP | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
SecureKey | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+ 4 | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
generate($len = 40) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
setAlgorithm(KeyAlgorithmInterface $algorithm) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+ |||
getAlgorithm() | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 2 | +
+
+
+ |
+ 100.00% |
+ 4 / 4 |
+
<?php | |
/** | |
* OAuth 2.0 Secure key generator | |
* | |
* @package php-loep/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) 2013 PHP League of Extraordinary Packages | |
* @license http://mit-license.org/ | |
* @link http://github.com/php-loep/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Util; | |
use League\OAuth2\Server\Util\KeyAlgorithm\DefaultAlgorithm; | |
use League\OAuth2\Server\Util\KeyAlgorithm\KeyAlgorithmInterface; | |
/** | |
* SecureKey class | |
*/ | |
class SecureKey | |
{ | |
protected static $algorithm; | |
/** | |
* Generate a new unique code | |
* | |
* @param integer $len Length of the generated code | |
* | |
* @return string | |
*/ | |
public static function generate($len = 40) | |
{ | |
return self::getAlgorithm()->generate($len); | |
} | |
/** | |
* @param KeyAlgorithmInterface $algorithm | |
*/ | |
public static function setAlgorithm(KeyAlgorithmInterface $algorithm) | |
{ | |
self::$algorithm = $algorithm; | |
} | |
/** | |
* @return KeyAlgorithmInterface | |
*/ | |
public static function getAlgorithm() | |
{ | |
if (is_null(self::$algorithm)) { | |
self::$algorithm = new DefaultAlgorithm(); | |
} | |
return self::$algorithm; | |
} | |
} |
Class | +Coverage | +
---|
Class | +CRAP | +
---|
Method | +Coverage | +
---|
Method | +CRAP | +
---|
+ | Code Coverage |
+ ||||||||
+ | Lines |
+ Functions and Methods |
+ Classes and Traits |
+ ||||||
Total | +
+
+
+ |
+ 100.00% |
+ 15 / 15 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
KeyAlgorithm | +
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
RedirectUri.php | +
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
SecureKey.php | +
+
+
+ |
+ 100.00% |
+ 7 / 7 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
Class | +Coverage | +
---|---|
UserAuthenticationFailedEvent | 75% |
ClientAuthenticationFailedEvent | 75% |
AccessTokenEntity | 84% |
Class | +CRAP | +
---|---|
AccessTokenEntity | 9 |
Method | +Coverage | +
---|---|
getRequest | 0% |
getRequest | 0% |
hasScope | 0% |
formatScopes | 88% |
Method | +CRAP | +
---|---|
hasScope | 6 |
formatScopes | 4 |
+ | Code Coverage |
+ ||||||||
+ | Lines |
+ Functions and Methods |
+ Classes and Traits |
+ ||||||
Total | +
+
+
+ |
+ 99.01% |
+ 702 / 709 |
+
+
+
+ |
+ 97.32% |
+ 145 / 149 |
+
+
+
+ |
+ 89.19% |
+ 33 / 37 |
+
Entity | +
+
+
+ |
+ 97.08% |
+ 166 / 171 |
+
+
+
+ |
+ 96.15% |
+ 50 / 52 |
+
+
+
+ |
+ 75.00% |
+ 6 / 8 |
+
Event | +
+
+
+ |
+ 83.33% |
+ 10 / 12 |
+
+
+
+ |
+ 77.78% |
+ 7 / 9 |
+
+
+
+ |
+ 33.33% |
+ 1 / 3 |
+
Exception | +
+
+
+ |
+ 100.00% |
+ 67 / 67 |
+
+
+
+ |
+ 100.00% |
+ 15 / 15 |
+
+
+
+ |
+ 100.00% |
+ 12 / 12 |
+
Grant | +
+
+
+ |
+ 100.00% |
+ 312 / 312 |
+
+
+
+ |
+ 100.00% |
+ 19 / 19 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+
Storage | +
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
TokenType | +
+
+
+ |
+ 100.00% |
+ 18 / 18 |
+
+
+
+ |
+ 100.00% |
+ 6 / 6 |
+
+
+
+ |
+ 100.00% |
+ 2 / 2 |
+
Util | +
+
+
+ |
+ 100.00% |
+ 15 / 15 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+
+
+
+ |
+ 100.00% |
+ 3 / 3 |
+
AbstractServer.php | +
+
+
+ |
+ 100.00% |
+ 44 / 44 |
+
+
+
+ |
+ 100.00% |
+ 20 / 20 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
AuthorizationServer.php | +
+
+
+ |
+ 100.00% |
+ 38 / 38 |
+
+
+
+ |
+ 100.00% |
+ 16 / 16 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
ResourceServer.php | +
+
+
+ |
+ 100.00% |
+ 29 / 29 |
+
+
+
+ |
+ 100.00% |
+ 5 / 5 |
+
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+
=i.length)return n;var r=[],u=o[e++];return n.forEach(function(n,u){r.push({key:n,values:t(u,e)})}),u?r.sort(function(n,t){return u(n.key,t.key)}):r}var e,r,u={},i=[],o=[];return u.map=function(t,e){return n(e,t,0)},u.entries=function(e){return t(n(Bo.map,e,0),0)},u.key=function(n){return i.push(n),u},u.sortKeys=function(n){return o[i.length-1]=n,u},u.sortValues=function(n){return e=n,u},u.rollup=function(n){return r=n,u},u},Bo.set=function(n){var t=new v;if(n)for(var e=0,r=n.length;r>e;++e)t.add(n[e]);return t},o(v,{has:s,add:function(n){return this._[c(n+="")]=!0,n},remove:f,values:h,size:g,empty:p,forEach:function(n){for(var t in this._)n.call(this,l(t))}}),Bo.behavior={},Bo.rebind=function(n,t){for(var e,r=1,u=arguments.length;++r=0&&(r=n.slice(e+1),n=n.slice(0,e)),n)return arguments.length<2?this[n].on(r):this[n].on(r,t);if(2===arguments.length){if(null==t)for(n in this)this.hasOwnProperty(n)&&this[n].on(r,null);return this}},Bo.event=null,Bo.requote=function(n){return n.replace(ha,"\\$&")};var ha=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g,ga={}.__proto__?function(n,t){n.__proto__=t}:function(n,t){for(var e in t)n[e]=t[e]},pa=function(n,t){return t.querySelector(n)},va=function(n,t){return t.querySelectorAll(n)},da=Ko.matches||Ko[m(Ko,"matchesSelector")],ma=function(n,t){return da.call(n,t)};"function"==typeof Sizzle&&(pa=function(n,t){return Sizzle(n,t)[0]||null},va=Sizzle,ma=Sizzle.matchesSelector),Bo.selection=function(){return _a};var ya=Bo.selection.prototype=[];ya.select=function(n){var t,e,r,u,i=[];n=k(n);for(var o=-1,a=this.length;++o=0&&(e=n.slice(0,t),n=n.slice(t+1)),xa.hasOwnProperty(e)?{space:xa[e],local:n}:n}},ya.attr=function(n,t){if(arguments.length<2){if("string"==typeof n){var e=this.node();return n=Bo.ns.qualify(n),n.local?e.getAttributeNS(n.space,n.local):e.getAttribute(n)}for(t in n)this.each(A(t,n[t]));return this}return this.each(A(n,t))},ya.classed=function(n,t){if(arguments.length<2){if("string"==typeof n){var e=this.node(),r=(n=z(n)).length,u=-1;if(t=e.classList){for(;++u =0?n.slice(0,t):n,r=t>=0?n.slice(t+1):"in";return e=ul.get(e)||rl,r=il.get(r)||Et,yu(r(e.apply(null,Wo.call(arguments,1))))},Bo.interpolateHcl=Lu,Bo.interpolateHsl=Tu,Bo.interpolateLab=qu,Bo.interpolateRound=Ru,Bo.transform=function(n){var t=Go.createElementNS(Bo.ns.prefix.svg,"g");return(Bo.transform=function(n){if(null!=n){t.setAttribute("transform",n);var e=t.transform.baseVal.consolidate()}return new Du(e?e.matrix:ol)})(n)},Du.prototype.toString=function(){return"translate("+this.translate+")rotate("+this.rotate+")skewX("+this.skew+")scale("+this.scale+")"};var ol={a:1,b:0,c:0,d:1,e:0,f:0};Bo.interpolateTransform=Fu,Bo.layout={},Bo.layout.bundle=function(){return function(n){for(var t=[],e=-1,r=n.length;++e