@@ -83,8 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){ |
85 | 85 | $_SESSION[$this->sessionVar][$service] = $token; |
86 | - } |
|
87 | - else{ |
|
86 | + } else{ |
|
88 | 87 | $_SESSION[$this->sessionVar] = [$service => $token]; |
89 | 88 | } |
90 | 89 | |
@@ -153,8 +152,7 @@ discard block |
||
153 | 152 | |
154 | 153 | if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){ |
155 | 154 | $_SESSION[$this->stateVar][$service] = $state; |
156 | - } |
|
157 | - else{ |
|
155 | + } else{ |
|
158 | 156 | $_SESSION[$this->stateVar] = [$service => $state]; |
159 | 157 | } |
160 | 158 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\OAuth\Core\AccessToken; |
16 | 16 | use chillerlan\Traits\ImmutableSettingsInterface; |
17 | 17 | |
18 | -class SessionStorage extends OAuthStorageAbstract{ |
|
18 | +class SessionStorage extends OAuthStorageAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var bool |
@@ -37,21 +37,21 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param \chillerlan\Traits\ImmutableSettingsInterface|null $options |
39 | 39 | */ |
40 | - public function __construct(ImmutableSettingsInterface $options = null){ |
|
40 | + public function __construct(ImmutableSettingsInterface $options = null) { |
|
41 | 41 | parent::__construct($options); |
42 | 42 | |
43 | 43 | $this->sessionVar = $this->options->sessionTokenVar; |
44 | 44 | $this->stateVar = $this->options->sessionStateVar; |
45 | 45 | |
46 | - if($this->options->sessionStart && !$this->sessionIsActive()){ |
|
46 | + if ($this->options->sessionStart && !$this->sessionIsActive()) { |
|
47 | 47 | session_start(); |
48 | 48 | } |
49 | 49 | |
50 | - if(!isset($_SESSION[$this->sessionVar])){ |
|
50 | + if (!isset($_SESSION[$this->sessionVar])) { |
|
51 | 51 | $_SESSION[$this->sessionVar] = []; |
52 | 52 | } |
53 | 53 | |
54 | - if(!isset($_SESSION[$this->stateVar])){ |
|
54 | + if (!isset($_SESSION[$this->stateVar])) { |
|
55 | 55 | $_SESSION[$this->stateVar] = []; |
56 | 56 | } |
57 | 57 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @codeCoverageIgnore |
64 | 64 | */ |
65 | - public function __destruct(){ |
|
66 | - if($this->options->sessionStart){ |
|
65 | + public function __destruct() { |
|
66 | + if ($this->options->sessionStart) { |
|
67 | 67 | session_write_close(); |
68 | 68 | } |
69 | 69 | } |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{ |
78 | 78 | $token = $token->__toJSON(); |
79 | 79 | |
80 | - if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){ |
|
80 | + if (isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])) { |
|
81 | 81 | $_SESSION[$this->sessionVar][$service] = $token; |
82 | 82 | } |
83 | - else{ |
|
83 | + else { |
|
84 | 84 | $_SESSION[$this->sessionVar] = [$service => $token]; |
85 | 85 | } |
86 | 86 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function getAccessToken(string $service):AccessToken{ |
97 | 97 | |
98 | - if($this->hasAccessToken($service)){ |
|
98 | + if ($this->hasAccessToken($service)) { |
|
99 | 99 | return (new AccessToken)->__fromJSON($_SESSION[$this->sessionVar][$service]); |
100 | 100 | } |
101 | 101 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function clearAccessToken(string $service):OAuthStorageInterface{ |
120 | 120 | |
121 | - if(array_key_exists($service, $_SESSION[$this->sessionVar])){ |
|
121 | + if (array_key_exists($service, $_SESSION[$this->sessionVar])) { |
|
122 | 122 | unset($_SESSION[$this->sessionVar][$service]); |
123 | 123 | } |
124 | 124 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function clearAllAccessTokens():OAuthStorageInterface{ |
132 | 132 | |
133 | - foreach(array_keys($_SESSION[$this->sessionVar]) as $service){ |
|
133 | + foreach (array_keys($_SESSION[$this->sessionVar]) as $service) { |
|
134 | 134 | unset($_SESSION[$this->sessionVar][$service]); // trigger the memzero destructor |
135 | 135 | } |
136 | 136 | |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function storeCSRFState(string $service, string $state):OAuthStorageInterface{ |
149 | 149 | |
150 | - if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){ |
|
150 | + if (isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])) { |
|
151 | 151 | $_SESSION[$this->stateVar][$service] = $state; |
152 | 152 | } |
153 | - else{ |
|
153 | + else { |
|
154 | 154 | $_SESSION[$this->stateVar] = [$service => $state]; |
155 | 155 | } |
156 | 156 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function getCSRFState(string $service):string{ |
167 | 167 | |
168 | - if($this->hasCSRFState($service)){ |
|
168 | + if ($this->hasCSRFState($service)) { |
|
169 | 169 | return $_SESSION[$this->stateVar][$service]; |
170 | 170 | } |
171 | 171 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function clearCSRFState(string $service):OAuthStorageInterface{ |
190 | 190 | |
191 | - if(array_key_exists($service, $_SESSION[$this->stateVar])){ |
|
191 | + if (array_key_exists($service, $_SESSION[$this->stateVar])) { |
|
192 | 192 | unset($_SESSION[$this->stateVar][$service]); |
193 | 193 | } |
194 | 194 |
@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\OAuth\Core\AccessToken; |
16 | 16 | |
17 | -interface OAuthStorageInterface{ |
|
17 | +interface OAuthStorageInterface { |
|
18 | 18 | |
19 | 19 | public const TOKEN_NONCE = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"; |
20 | 20 |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | ]; |
62 | 62 | |
63 | 63 | /** @var \chillerlan\Traits\ContainerInterface $options */ |
64 | -$options = new class($options_arr) extends OAuthOptions{ |
|
64 | +$options = new class($options_arr) extends OAuthOptions { |
|
65 | 65 | use DatabaseOptionsTrait, LogOptionsTrait; |
66 | 66 | |
67 | 67 | protected $sleep; |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | $logger->addInstance(new ConsoleLog($options), 'console'); |
72 | 72 | |
73 | 73 | /** @var \chillerlan\HTTP\HTTPClientInterface $http */ |
74 | -$http = new class($options) extends HTTPClientAbstract{ |
|
74 | +$http = new class($options) extends HTTPClientAbstract { |
|
75 | 75 | |
76 | 76 | protected $client; |
77 | 77 | |
78 | - public function __construct(ContainerInterface $options){ |
|
78 | + public function __construct(ContainerInterface $options) { |
|
79 | 79 | parent::__construct($options); |
80 | 80 | $this->client = new CurlClient($this->options); |
81 | 81 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @property string $ca_info |
56 | 56 | * @property int $max_redirects |
57 | 57 | */ |
58 | -class OAuthOptions implements ImmutableSettingsInterface{ |
|
58 | +class OAuthOptions implements ImmutableSettingsInterface { |
|
59 | 59 | use OAuthOptionsTrait, HTTPOptionsTrait, MemzeroDestructorTrait, ImmutableSettingsContainer{ |
60 | 60 | __construct as protected containerConstruct; |
61 | 61 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @param iterable|null $properties |
67 | 67 | */ |
68 | - public function __construct(iterable $properties = null){ |
|
68 | + public function __construct(iterable $properties = null) { |
|
69 | 69 | // enable encryption by default if possible... |
70 | 70 | $this->useEncryption = extension_loaded('sodium'); |
71 | 71 |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param \chillerlan\Traits\ImmutableSettingsInterface $options |
91 | 91 | * @param \Psr\Log\LoggerInterface|null $logger |
92 | 92 | */ |
93 | - public function __construct(HTTPClientInterface $http, OAuthStorageInterface $storage, ImmutableSettingsInterface $options, LoggerInterface $logger = null){ |
|
93 | + public function __construct(HTTPClientInterface $http, OAuthStorageInterface $storage, ImmutableSettingsInterface $options, LoggerInterface $logger = null) { |
|
94 | 94 | $this->setHTTPClient($http); |
95 | 95 | |
96 | 96 | $this->storage = $storage; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
101 | 101 | |
102 | - if($this instanceof ApiClientInterface){ |
|
102 | + if ($this instanceof ApiClientInterface) { |
|
103 | 103 | $this->loadEndpoints(); |
104 | 104 | } |
105 | 105 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use chillerlan\OAuth\Core\AccessToken; |
17 | 17 | use chillerlan\Traits\ImmutableSettingsInterface; |
18 | 18 | |
19 | -class DBStorage extends OAuthStorageAbstract{ |
|
19 | +class DBStorage extends OAuthStorageAbstract { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @var \chillerlan\Database\Database |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @throws \chillerlan\OAuth\Storage\OAuthStorageException |
33 | 33 | */ |
34 | - public function __construct(ImmutableSettingsInterface $options, Database $db){ |
|
34 | + public function __construct(ImmutableSettingsInterface $options, Database $db) { |
|
35 | 35 | parent::__construct($options); |
36 | 36 | |
37 | - if(!$this->options->dbTokenTable || !$this->options->dbProviderTable){ |
|
37 | + if (!$this->options->dbTokenTable || !$this->options->dbProviderTable) { |
|
38 | 38 | throw new OAuthStorageException('invalid table config'); |
39 | 39 | } |
40 | 40 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{ |
63 | 63 | $providers = $this->getProviders(); |
64 | 64 | |
65 | - if(empty($providers) || !isset($providers[$service])){ |
|
65 | + if (empty($providers) || !isset($providers[$service])) { |
|
66 | 66 | throw new OAuthStorageException('unknown service'); |
67 | 67 | } |
68 | 68 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | $this->options->dbTokenTableExpires => $token->expires, |
74 | 74 | ]; |
75 | 75 | |
76 | - if($this->hasAccessToken($service) === true){ |
|
76 | + if ($this->hasAccessToken($service) === true) { |
|
77 | 77 | $this->db->update |
78 | 78 | ->table($this->options->dbTokenTable) |
79 | 79 | ->set($values) |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | ->where($this->options->dbTokenTableLabel, $this->getLabel($service)) |
108 | 108 | ->query(); |
109 | 109 | |
110 | - if(is_bool($r) || $r->length < 1){ |
|
110 | + if (is_bool($r) || $r->length < 1) { |
|
111 | 111 | throw new OAuthStorageException('token not found'); |
112 | 112 | } |
113 | 113 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | ->where($this->options->dbTokenTableLabel, $this->getLabel($service)) |
188 | 188 | ->query(); |
189 | 189 | |
190 | - if(is_bool($r) || $r->length < 1){ |
|
190 | + if (is_bool($r) || $r->length < 1) { |
|
191 | 191 | throw new OAuthStorageException('state not found'); |
192 | 192 | } |
193 | 193 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | ->where($this->options->dbTokenTableLabel, $this->getLabel($service)) |
208 | 208 | ->query(); |
209 | 209 | |
210 | - if(is_bool($r) || $r->length < 1 || empty(trim($r[0]->state))){ |
|
210 | + if (is_bool($r) || $r->length < 1 || empty(trim($r[0]->state))) { |
|
211 | 211 | return false; |
212 | 212 | } |
213 | 213 |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param \chillerlan\Traits\ImmutableSettingsInterface|null $options |
35 | 35 | * @param \Psr\Log\LoggerInterface|null $logger |
36 | 36 | */ |
37 | - public function __construct(ImmutableSettingsInterface $options = null, LoggerInterface $logger = null){ |
|
37 | + public function __construct(ImmutableSettingsInterface $options = null, LoggerInterface $logger = null) { |
|
38 | 38 | $this->options = $options ?? new OAuthOptions; |
39 | 39 | $this->logger = $logger ?? new NullLogger; |
40 | 40 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | unset($token); |
51 | 51 | |
52 | - if($this->options->useEncryption === true){ |
|
52 | + if ($this->options->useEncryption === true) { |
|
53 | 53 | return $this->encrypt($data); |
54 | 54 | } |
55 | 55 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function fromStorage(string $data):AccessToken{ |
65 | 65 | |
66 | - if($this->options->useEncryption === true){ |
|
66 | + if ($this->options->useEncryption === true) { |
|
67 | 67 | $data = $this->decrypt($data); |
68 | 68 | } |
69 | 69 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | protected function encrypt(string &$data):string { |
80 | 80 | |
81 | - if(function_exists('sodium_crypto_secretbox')){ |
|
81 | + if (function_exists('sodium_crypto_secretbox')) { |
|
82 | 82 | $box = sodium_crypto_secretbox($data, $this::TOKEN_NONCE, sodium_hex2bin($this->options->storageCryptoKey)); |
83 | 83 | |
84 | 84 | sodium_memzero($data); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | protected function decrypt(string $box):string { |
99 | 99 | |
100 | - if(function_exists('sodium_crypto_secretbox_open')){ |
|
100 | + if (function_exists('sodium_crypto_secretbox_open')) { |
|
101 | 101 | return sodium_crypto_secretbox_open(sodium_hex2bin($box), $this::TOKEN_NONCE, sodium_hex2bin($this->options->storageCryptoKey)); |
102 | 102 | } |
103 | 103 |