@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @property int $expires |
32 | 32 | * @property string $provider |
33 | 33 | */ |
34 | -class AccessToken implements ContainerInterface{ |
|
34 | +class AccessToken implements ContainerInterface { |
|
35 | 35 | use MemzeroDestructorTrait, Container{ |
36 | 36 | __construct as constructContainer; |
37 | 37 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @param array|null $properties |
100 | 100 | */ |
101 | - public function __construct(array $properties = null){ |
|
101 | + public function __construct(array $properties = null) { |
|
102 | 102 | $this->constructContainer($properties); |
103 | 103 | |
104 | 104 | $this->setExpiry($this->expires); |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return void |
114 | 114 | */ |
115 | - public function __set(string $property, $value){ |
|
115 | + public function __set(string $property, $value) { |
|
116 | 116 | |
117 | - if(property_exists($this, $property)){ |
|
117 | + if (property_exists($this, $property)) { |
|
118 | 118 | $property === 'expires' |
119 | 119 | ? $this->setExpiry($value) |
120 | 120 | : $this->{$property} = $value; |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | public function setExpiry(int $expires = null):AccessToken{ |
131 | 131 | $now = time(); |
132 | 132 | |
133 | - if($expires!== null){ |
|
134 | - $expires = intval($expires); |
|
133 | + if ($expires !== null) { |
|
134 | + $expires = intval($expires); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | $this->expires = $this::EOL_UNKNOWN; |
138 | 138 | |
139 | - if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){ |
|
139 | + if ($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES) { |
|
140 | 140 | $this->expires = $this::EOL_NEVER_EXPIRES; |
141 | 141 | } |
142 | - elseif($expires > $now){ |
|
142 | + elseif ($expires > $now) { |
|
143 | 143 | $this->expires = $expires; |
144 | 144 | } |
145 | - elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
145 | + elseif ($expires > 0 && $expires < $this::EXPIRY_MAX) { |
|
146 | 146 | $this->expires = $now + $expires; |
147 | 147 | } |
148 | 148 |
@@ -138,11 +138,9 @@ |
||
138 | 138 | |
139 | 139 | if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){ |
140 | 140 | $this->expires = $this::EOL_NEVER_EXPIRES; |
141 | - } |
|
142 | - elseif($expires > $now){ |
|
141 | + } elseif($expires > $now){ |
|
143 | 142 | $this->expires = $expires; |
144 | - } |
|
145 | - elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
143 | + } elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
146 | 144 | $this->expires = $now + $expires; |
147 | 145 | } |
148 | 146 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param \chillerlan\Traits\ContainerInterface|null $options |
37 | 37 | * @param \Psr\Log\LoggerInterface|null $logger |
38 | 38 | */ |
39 | - public function __construct(ContainerInterface $options = null, LoggerInterface $logger = null){ |
|
39 | + public function __construct(ContainerInterface $options = null, LoggerInterface $logger = null) { |
|
40 | 40 | $this->options = $options ?? new OAuthOptions; |
41 | 41 | $this->logger = $logger ?? new NullLogger; |
42 | 42 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | unset($token); |
53 | 53 | |
54 | - if($this->options->useEncryption === true){ |
|
54 | + if ($this->options->useEncryption === true) { |
|
55 | 55 | return $this->encrypt($data); |
56 | 56 | } |
57 | 57 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function fromStorage(string $data):AccessToken{ |
67 | 67 | |
68 | - if($this->options->useEncryption === true){ |
|
68 | + if ($this->options->useEncryption === true) { |
|
69 | 69 | $data = $this->decrypt($data); |
70 | 70 | } |
71 | 71 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | protected function encrypt(string &$data):string { |
82 | 82 | |
83 | - if(function_exists('sodium_crypto_secretbox')){ |
|
83 | + if (function_exists('sodium_crypto_secretbox')) { |
|
84 | 84 | $box = sodium_crypto_secretbox($data, $this::TOKEN_NONCE, sodium_hex2bin($this->options->storageCryptoKey)); |
85 | 85 | |
86 | 86 | sodium_memzero($data); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | protected function decrypt(string $box):string { |
101 | 101 | |
102 | - if(function_exists('sodium_crypto_secretbox_open')){ |
|
102 | + if (function_exists('sodium_crypto_secretbox_open')) { |
|
103 | 103 | return sodium_crypto_secretbox_open(sodium_hex2bin($box), $this::TOKEN_NONCE, sodium_hex2bin($this->options->storageCryptoKey)); |
104 | 104 | } |
105 | 105 |
@@ -14,4 +14,4 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\OAuth\OAuthException; |
16 | 16 | |
17 | -class OAuthStorageException extends OAuthException{} |
|
17 | +class OAuthStorageException extends OAuthException {} |
@@ -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 | /** |
20 | 20 | * @param string $service |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use chillerlan\OAuth\Core\AccessToken; |
17 | 17 | use chillerlan\Traits\ContainerInterface; |
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(ContainerInterface $options, Database $db){ |
|
34 | + public function __construct(ContainerInterface $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 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use chillerlan\OAuth\Core\AccessToken; |
16 | 16 | |
17 | -class MemoryStorage extends OAuthStorageAbstract{ |
|
17 | +class MemoryStorage extends OAuthStorageAbstract { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @var array |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function getAccessToken(string $service):AccessToken{ |
48 | 48 | |
49 | - if($this->hasAccessToken($service)){ |
|
49 | + if ($this->hasAccessToken($service)) { |
|
50 | 50 | return $this->tokens[$service]; |
51 | 51 | } |
52 | 52 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function clearAccessToken(string $service):OAuthStorageInterface{ |
71 | 71 | |
72 | - if(array_key_exists($service, $this->tokens)){ |
|
72 | + if (array_key_exists($service, $this->tokens)) { |
|
73 | 73 | unset($this->tokens[$service]); |
74 | 74 | } |
75 | 75 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function clearAllAccessTokens():OAuthStorageInterface{ |
83 | 83 | |
84 | - foreach(array_keys($this->tokens) as $service){ |
|
84 | + foreach (array_keys($this->tokens) as $service) { |
|
85 | 85 | unset($this->tokens[$service]); // trigger the memzero destructor |
86 | 86 | } |
87 | 87 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function getCSRFState(string $service):string{ |
112 | 112 | |
113 | - if($this->hasCSRFState($service)){ |
|
113 | + if ($this->hasCSRFState($service)) { |
|
114 | 114 | return $this->states[$service]; |
115 | 115 | } |
116 | 116 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function clearCSRFState(string $service):OAuthStorageInterface{ |
135 | 135 | |
136 | - if(array_key_exists($service, $this->states)){ |
|
136 | + if (array_key_exists($service, $this->states)) { |
|
137 | 137 | unset($this->states[$service]); |
138 | 138 | } |
139 | 139 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\OAuth\Core\AccessToken; |
16 | 16 | use chillerlan\Traits\ContainerInterface; |
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\ContainerInterface|null $options |
39 | 39 | */ |
40 | - public function __construct(ContainerInterface $options = null){ |
|
40 | + public function __construct(ContainerInterface $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 | |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * Destructor. |
62 | 62 | */ |
63 | - public function __destruct(){ |
|
64 | - if($this->options->sessionStart){ |
|
63 | + public function __destruct() { |
|
64 | + if ($this->options->sessionStart) { |
|
65 | 65 | session_write_close(); |
66 | 66 | } |
67 | 67 | } |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{ |
76 | 76 | $token = $token->__toJSON(); |
77 | 77 | |
78 | - if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){ |
|
78 | + if (isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])) { |
|
79 | 79 | $_SESSION[$this->sessionVar][$service] = $token; |
80 | 80 | } |
81 | - else{ |
|
81 | + else { |
|
82 | 82 | $_SESSION[$this->sessionVar] = [$service => $token]; |
83 | 83 | } |
84 | 84 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function getAccessToken(string $service):AccessToken{ |
95 | 95 | |
96 | - if($this->hasAccessToken($service)){ |
|
96 | + if ($this->hasAccessToken($service)) { |
|
97 | 97 | return (new AccessToken)->__fromJSON($_SESSION[$this->sessionVar][$service]); |
98 | 98 | } |
99 | 99 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function clearAccessToken(string $service):OAuthStorageInterface{ |
118 | 118 | |
119 | - if(array_key_exists($service, $_SESSION[$this->sessionVar])){ |
|
119 | + if (array_key_exists($service, $_SESSION[$this->sessionVar])) { |
|
120 | 120 | unset($_SESSION[$this->sessionVar][$service]); |
121 | 121 | } |
122 | 122 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function clearAllAccessTokens():OAuthStorageInterface{ |
130 | 130 | |
131 | - foreach(array_keys($_SESSION[$this->sessionVar]) as $service){ |
|
131 | + foreach (array_keys($_SESSION[$this->sessionVar]) as $service) { |
|
132 | 132 | unset($_SESSION[$this->sessionVar][$service]); // trigger the memzero destructor |
133 | 133 | } |
134 | 134 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function storeCSRFState(string $service, string $state):OAuthStorageInterface{ |
147 | 147 | |
148 | - if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){ |
|
148 | + if (isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])) { |
|
149 | 149 | $_SESSION[$this->stateVar][$service] = $state; |
150 | 150 | } |
151 | - else{ |
|
151 | + else { |
|
152 | 152 | $_SESSION[$this->stateVar] = [$service => $state]; |
153 | 153 | } |
154 | 154 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function getCSRFState(string $service):string{ |
165 | 165 | |
166 | - if($this->hasCSRFState($service)){ |
|
166 | + if ($this->hasCSRFState($service)) { |
|
167 | 167 | return $_SESSION[$this->stateVar][$service]; |
168 | 168 | } |
169 | 169 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public function clearCSRFState(string $service):OAuthStorageInterface{ |
188 | 188 | |
189 | - if(array_key_exists($service, $_SESSION[$this->stateVar])){ |
|
189 | + if (array_key_exists($service, $_SESSION[$this->stateVar])) { |
|
190 | 190 | unset($_SESSION[$this->stateVar][$service]); |
191 | 191 | } |
192 | 192 |
@@ -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 |