From 262ce23fb9c67feff9caa013d1ead78145371311 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 5 Dec 2013 20:25:50 +0000 Subject: [PATCH] No longer need to inject auth server into grant --- src/League/OAuth2/Server/Authorization.php | 4 +++ src/League/OAuth2/Server/Grant/AuthCode.php | 10 ------- .../OAuth2/Server/Grant/ClientCredentials.php | 10 ------- src/League/OAuth2/Server/Grant/GrantTrait.php | 29 +++++++++++++++++++ .../Server/Grant/GrantTypeInterface.php | 3 +- src/League/OAuth2/Server/Grant/Implicit.php | 10 ------- src/League/OAuth2/Server/Grant/Password.php | 10 ------- .../OAuth2/Server/Grant/RefreshToken.php | 10 ------- 8 files changed, 34 insertions(+), 52 deletions(-) diff --git a/src/League/OAuth2/Server/Authorization.php b/src/League/OAuth2/Server/Authorization.php index 4dec4695..c5d63d2e 100644 --- a/src/League/OAuth2/Server/Authorization.php +++ b/src/League/OAuth2/Server/Authorization.php @@ -244,6 +244,10 @@ class Authorization if (is_null($identifier)) { $identifier = $grantType->getIdentifier(); } + + // Inject server into grant + $grantType->setAuthorizationServer($this); + $this->grantTypes[$identifier] = $grantType; if ( ! is_null($grantType->getResponseType())) { diff --git a/src/League/OAuth2/Server/Grant/AuthCode.php b/src/League/OAuth2/Server/Grant/AuthCode.php index 79a541af..bf968980 100644 --- a/src/League/OAuth2/Server/Grant/AuthCode.php +++ b/src/League/OAuth2/Server/Grant/AuthCode.php @@ -56,16 +56,6 @@ class AuthCode implements GrantTypeInterface { */ protected $authTokenTTL = 600; - /** - * Constructor - * @param Authorization $authServer Authorization server instance - * @return void - */ - public function __construct(Authorization $authServer) - { - $this->authServer = $authServer; - } - /** * Override the default access token expire time * @param int $authTokenTTL diff --git a/src/League/OAuth2/Server/Grant/ClientCredentials.php b/src/League/OAuth2/Server/Grant/ClientCredentials.php index 4d53bf23..aa072d09 100644 --- a/src/League/OAuth2/Server/Grant/ClientCredentials.php +++ b/src/League/OAuth2/Server/Grant/ClientCredentials.php @@ -50,16 +50,6 @@ class ClientCredentials implements GrantTypeInterface { */ protected $accessTokenTTL = null; - /** - * Constructor - * @param Authorization $authServer Authorization server instance - * @return void - */ - public function __construct(Authorization $authServer) - { - $this->authServer = $authServer; - } - /** * Return the identifier * @return string diff --git a/src/League/OAuth2/Server/Grant/GrantTrait.php b/src/League/OAuth2/Server/Grant/GrantTrait.php index e052ce57..efbcf22f 100644 --- a/src/League/OAuth2/Server/Grant/GrantTrait.php +++ b/src/League/OAuth2/Server/Grant/GrantTrait.php @@ -11,8 +11,26 @@ namespace League\OAuth2\Server\Grant; +use League\OAuth2\Server\Authorization; + trait GrantTrait { + /** + * Constructor + * @param Authorization $authServer Authorization server instance + * @return void + */ + public function __construct(Authorization $authServer = null) + { + // @codeCoverageIgnoreStart + if ($authServer instanceof Authorization) { + trigger_error( + 'Server is now automatically injected into grant as of v3.1 of this library', + E_USER_DEPRECATED + ); + } // @codeCoverageIgnoreEnd + } + /** * Return the identifier * @return string @@ -42,4 +60,15 @@ trait GrantTrait { return $this; } + /** + * Inject the authorization server into the grant + * @param Authorization $authServer The authorization server instance + * @return self + */ + public function setAuthorizationServer(Authorization $authServer) + { + $this->authServer = $authServer; + return $this; + } + } \ No newline at end of file diff --git a/src/League/OAuth2/Server/Grant/GrantTypeInterface.php b/src/League/OAuth2/Server/Grant/GrantTypeInterface.php index ec0b906b..2301bd4e 100644 --- a/src/League/OAuth2/Server/Grant/GrantTypeInterface.php +++ b/src/League/OAuth2/Server/Grant/GrantTypeInterface.php @@ -23,10 +23,9 @@ interface GrantTypeInterface { /** * Constructor - * @param Authorization $authServer Authorization server instance * @return void */ - public function __construct(Authorization $authServer); + public function __construct(Authorization $authServer = null); /** * Complete the grant flow diff --git a/src/League/OAuth2/Server/Grant/Implicit.php b/src/League/OAuth2/Server/Grant/Implicit.php index a71afed5..a41c05a6 100644 --- a/src/League/OAuth2/Server/Grant/Implicit.php +++ b/src/League/OAuth2/Server/Grant/Implicit.php @@ -50,16 +50,6 @@ class Implicit implements GrantTypeInterface { */ protected $accessTokenTTL = null; - /** - * Constructor - * @param Authorization $authServer Authorization server instance - * @return void - */ - public function __construct(Authorization $authServer) - { - $this->authServer = $authServer; - } - /** * Complete the client credentials grant * @param null|array $inputParams diff --git a/src/League/OAuth2/Server/Grant/Password.php b/src/League/OAuth2/Server/Grant/Password.php index a81a62c3..54410586 100644 --- a/src/League/OAuth2/Server/Grant/Password.php +++ b/src/League/OAuth2/Server/Grant/Password.php @@ -56,16 +56,6 @@ class Password implements GrantTypeInterface { */ protected $accessTokenTTL = null; - /** - * Constructor - * @param Authorization $authServer Authorization server instance - * @return void - */ - public function __construct(Authorization $authServer) - { - $this->authServer = $authServer; - } - /** * Set the callback to verify a user's username and password * @param callable $callback The callback function diff --git a/src/League/OAuth2/Server/Grant/RefreshToken.php b/src/League/OAuth2/Server/Grant/RefreshToken.php index 4c4664f3..baea674a 100644 --- a/src/League/OAuth2/Server/Grant/RefreshToken.php +++ b/src/League/OAuth2/Server/Grant/RefreshToken.php @@ -62,16 +62,6 @@ class RefreshToken implements GrantTypeInterface { */ protected $rotateRefreshTokens = false; - /** - * Constructor - * @param Authorization $authServer Authorization server instance - * @return void - */ - public function __construct(Authorization $authServer) - { - $this->authServer = $authServer; - } - /** * Set the TTL of the refresh token * @param int $refreshTokenTTL