@@ -13,7 +13,7 @@ |
||
| 13 | 13 | /** |
| 14 | 14 | * The settings for the OAuth provider |
| 15 | 15 | */ |
| 16 | -trait OAuthOptionsTrait{ |
|
| 16 | +trait OAuthOptionsTrait { |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * The application key (or id) given by your provider |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | * |
| 16 | 16 | * @link https://tools.ietf.org/html/rfc6749#section-4.4 |
| 17 | 17 | */ |
| 18 | -interface ClientCredentials{ |
|
| 18 | +interface ClientCredentials { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * Obtains an OAuth2 client credentials token and returns an AccessToken |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | /** |
| 14 | 14 | * Specifies the basic methods for an OAuth1 provider. |
| 15 | 15 | */ |
| 16 | -interface OAuth1Interface extends OAuthInterface{ |
|
| 16 | +interface OAuth1Interface extends OAuthInterface { |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Obtains an OAuth1 request token and returns an AccessToken object for use in the authentication request. |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | * |
| 16 | 16 | * @link https://tools.ietf.org/html/rfc6749#section-10.12 |
| 17 | 17 | */ |
| 18 | -interface CSRFToken{ |
|
| 18 | +interface CSRFToken { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * Checks whether the CSRF state was set and verifies against the last known state. |
@@ -83,11 +83,9 @@ |
||
| 83 | 83 | |
| 84 | 84 | if(empty($data)){ |
| 85 | 85 | throw new ProviderException('unable to parse token response'); |
| 86 | - } |
|
| 87 | - elseif(isset($data['error'])){ |
|
| 86 | + } elseif(isset($data['error'])){ |
|
| 88 | 87 | throw new ProviderException('error retrieving access token: '.$data['error']); |
| 89 | - } |
|
| 90 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
| 88 | + } elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
| 91 | 89 | throw new ProviderException('invalid token'); |
| 92 | 90 | } |
| 93 | 91 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | /** |
| 29 | 29 | * Implements an abstract OAuth1 provider with all methods required by the OAuth1Interface. |
| 30 | 30 | */ |
| 31 | -abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface{ |
|
| 31 | +abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface { |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * The request OAuth1 token URL |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | ->withHeader('Content-Length', '0') // tumblr requires a content-length header set |
| 68 | 68 | ; |
| 69 | 69 | |
| 70 | - foreach($this->authHeaders as $header => $value){ |
|
| 70 | + foreach ($this->authHeaders as $header => $value) { |
|
| 71 | 71 | $request = $request->withAddedHeader($header, $value); |
| 72 | 72 | } |
| 73 | 73 | |
@@ -84,20 +84,20 @@ discard block |
||
| 84 | 84 | protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{ |
| 85 | 85 | $data = QueryUtil::parse(MessageUtil::decompress($response)); |
| 86 | 86 | |
| 87 | - if(empty($data)){ |
|
| 87 | + if (empty($data)) { |
|
| 88 | 88 | throw new ProviderException('unable to parse token response'); |
| 89 | 89 | } |
| 90 | - elseif(isset($data['error'])){ |
|
| 90 | + elseif (isset($data['error'])) { |
|
| 91 | 91 | throw new ProviderException('error retrieving access token: '.$data['error']); |
| 92 | 92 | } |
| 93 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
| 93 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
| 94 | 94 | throw new ProviderException('invalid token'); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if( |
|
| 97 | + if ( |
|
| 98 | 98 | $checkCallbackConfirmed |
| 99 | 99 | && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') |
| 100 | - ){ |
|
| 100 | + ) { |
|
| 101 | 101 | throw new ProviderException('oauth callback unconfirmed'); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{ |
| 134 | 134 | $parsed = QueryUtil::parseUrl($url); |
| 135 | 135 | |
| 136 | - if(!isset($parsed['host']) || !isset($parsed['scheme']) || !in_array($parsed['scheme'], ['http', 'https'], true)){ |
|
| 136 | + if (!isset($parsed['host']) || !isset($parsed['scheme']) || !in_array($parsed['scheme'], ['http', 'https'], true)) { |
|
| 137 | 137 | throw new ProviderException('getSignature: invalid url'); |
| 138 | 138 | } |
| 139 | 139 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | ]); |
| 151 | 151 | |
| 152 | 152 | // https://tools.ietf.org/html/rfc5849#section-3.4.2 |
| 153 | - $key = array_map('rawurlencode', [ |
|
| 153 | + $key = array_map('rawurlencode', [ |
|
| 154 | 154 | $this->options->secret, |
| 155 | 155 | ($accessTokenSecret ?? ''), |
| 156 | 156 | ]); |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | $token->accessTokenSecret |
| 198 | 198 | ); |
| 199 | 199 | |
| 200 | - if(isset($query['oauth_session_handle'])){ |
|
| 200 | + if (isset($query['oauth_session_handle'])) { |
|
| 201 | 201 | $parameters['oauth_session_handle'] = $query['oauth_session_handle']; // @codeCoverageIgnore |
| 202 | 202 | } |
| 203 | 203 | |
@@ -16,6 +16,6 @@ |
||
| 16 | 16 | /** |
| 17 | 17 | * This class holds all settings related to the OAuth provider as well as the default HTTP client. |
| 18 | 18 | */ |
| 19 | -class OAuthOptions extends SettingsContainerAbstract{ |
|
| 19 | +class OAuthOptions extends SettingsContainerAbstract { |
|
| 20 | 20 | use OAuthOptionsTrait, HTTPOptionsTrait; |
| 21 | 21 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * Implements a memory storage adapter. Memory storage is not persistent as tokens are only stored during script runtime. |
| 19 | 19 | */ |
| 20 | -class MemoryStorage extends OAuthStorageAbstract{ |
|
| 20 | +class MemoryStorage extends OAuthStorageAbstract { |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * the token storage array |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function getAccessToken(string $service = null):AccessToken{ |
| 45 | 45 | |
| 46 | - if($this->hasAccessToken($service)){ |
|
| 46 | + if ($this->hasAccessToken($service)) { |
|
| 47 | 47 | return $this->tokens[$this->getServiceName($service)]; |
| 48 | 48 | } |
| 49 | 49 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | public function clearAccessToken(string $service = null):OAuthStorageInterface{ |
| 66 | 66 | $serviceName = $this->getServiceName($service); |
| 67 | 67 | |
| 68 | - if(array_key_exists($serviceName, $this->tokens)){ |
|
| 68 | + if (array_key_exists($serviceName, $this->tokens)) { |
|
| 69 | 69 | unset($this->tokens[$serviceName]); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | public function clearAllAccessTokens():OAuthStorageInterface{ |
| 79 | 79 | |
| 80 | - foreach(array_keys($this->tokens) as $service){ |
|
| 80 | + foreach (array_keys($this->tokens) as $service) { |
|
| 81 | 81 | unset($this->tokens[$service]); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function getCSRFState(string $service = null):string{ |
| 102 | 102 | |
| 103 | - if($this->hasCSRFState($service)){ |
|
| 103 | + if ($this->hasCSRFState($service)) { |
|
| 104 | 104 | return $this->states[$this->getServiceName($service)]; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | public function clearCSRFState(string $service = null):OAuthStorageInterface{ |
| 123 | 123 | $serviceName = $this->getServiceName($service); |
| 124 | 124 | |
| 125 | - if(array_key_exists($serviceName, $this->states)){ |
|
| 125 | + if (array_key_exists($serviceName, $this->states)) { |
|
| 126 | 126 | unset($this->states[$serviceName]); |
| 127 | 127 | } |
| 128 | 128 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | /** |
| 24 | 24 | * Implements a session storage adapter. Session storage is half persistent as tokens are stored for the duration of the session. |
| 25 | 25 | */ |
| 26 | -class SessionStorage extends OAuthStorageAbstract{ |
|
| 26 | +class SessionStorage extends OAuthStorageAbstract { |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * the key name for the token storage array in $_SESSION |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | /** |
| 39 | 39 | * SessionStorage constructor. |
| 40 | 40 | */ |
| 41 | - public function __construct(OAuthOptions|SettingsContainerInterface $options = null){ |
|
| 41 | + public function __construct(OAuthOptions|SettingsContainerInterface $options = null) { |
|
| 42 | 42 | parent::__construct($options); |
| 43 | 43 | |
| 44 | 44 | $this->tokenVar = $this->options->sessionTokenVar; |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | // Determine if the session has started. |
| 48 | 48 | // @link http://stackoverflow.com/a/18542272/1470961 |
| 49 | - if($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)){ |
|
| 49 | + if ($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)) { |
|
| 50 | 50 | session_start(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if(!isset($_SESSION[$this->tokenVar])){ |
|
| 53 | + if (!isset($_SESSION[$this->tokenVar])) { |
|
| 54 | 54 | $_SESSION[$this->tokenVar] = []; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if(!isset($_SESSION[$this->stateVar])){ |
|
| 57 | + if (!isset($_SESSION[$this->stateVar])) { |
|
| 58 | 58 | $_SESSION[$this->stateVar] = []; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @codeCoverageIgnore |
| 67 | 67 | */ |
| 68 | - public function __destruct(){ |
|
| 69 | - if($this->options->sessionStart){ |
|
| 68 | + public function __destruct() { |
|
| 69 | + if ($this->options->sessionStart) { |
|
| 70 | 70 | session_write_close(); |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function getAccessToken(string $service = null):AccessToken{ |
| 87 | 87 | |
| 88 | - if($this->hasAccessToken($service)){ |
|
| 88 | + if ($this->hasAccessToken($service)) { |
|
| 89 | 89 | return $this->fromStorage($_SESSION[$this->tokenVar][$this->getServiceName($service)]); |
| 90 | 90 | } |
| 91 | 91 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | public function clearAccessToken(string $service = null):OAuthStorageInterface{ |
| 106 | 106 | $serviceName = $this->getServiceName($service); |
| 107 | 107 | |
| 108 | - if(array_key_exists($serviceName, $_SESSION[$this->tokenVar])){ |
|
| 108 | + if (array_key_exists($serviceName, $_SESSION[$this->tokenVar])) { |
|
| 109 | 109 | unset($_SESSION[$this->tokenVar][$serviceName]); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | public function clearAllAccessTokens():OAuthStorageInterface{ |
| 119 | 119 | |
| 120 | - foreach(array_keys($_SESSION[$this->tokenVar]) as $service){ |
|
| 120 | + foreach (array_keys($_SESSION[$this->tokenVar]) as $service) { |
|
| 121 | 121 | unset($_SESSION[$this->tokenVar][$service]); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | public function getCSRFState(string $service = null):string{ |
| 142 | 142 | |
| 143 | - if($this->hasCSRFState($service)){ |
|
| 143 | + if ($this->hasCSRFState($service)) { |
|
| 144 | 144 | return $_SESSION[$this->stateVar][$this->getServiceName($service)]; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | public function clearCSRFState(string $service = null):OAuthStorageInterface{ |
| 161 | 161 | $serviceName = $this->getServiceName($service); |
| 162 | 162 | |
| 163 | - if(array_key_exists($serviceName, $_SESSION[$this->stateVar])){ |
|
| 163 | + if (array_key_exists($serviceName, $_SESSION[$this->stateVar])) { |
|
| 164 | 164 | unset($_SESSION[$this->stateVar][$serviceName]); |
| 165 | 165 | } |
| 166 | 166 | |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | /** |
| 17 | 17 | * Specifies the methods required for an OAuth storage adapter |
| 18 | 18 | */ |
| 19 | -interface OAuthStorageInterface extends LoggerAwareInterface{ |
|
| 19 | +interface OAuthStorageInterface extends LoggerAwareInterface { |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Sets the current service provider name |