@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @property \chillerlan\OAuth\Storage\TokenStorageInterface $storage |
22 | 22 | * @property \chillerlan\OAuth\OAuthOptions $options |
23 | 23 | */ |
24 | -trait OAuth2TokenRefreshTrait{ |
|
24 | +trait OAuth2TokenRefreshTrait { |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @param \chillerlan\OAuth\Token $token |
@@ -31,15 +31,15 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function refreshAccessToken(Token $token = null):Token{ |
33 | 33 | |
34 | - if($token === null){ |
|
34 | + if ($token === null) { |
|
35 | 35 | $token = $this->storage->getAccessToken($this->serviceName); |
36 | 36 | } |
37 | 37 | |
38 | 38 | $refreshToken = $token->refreshToken; |
39 | 39 | |
40 | - if(empty($refreshToken)){ |
|
40 | + if (empty($refreshToken)) { |
|
41 | 41 | |
42 | - if(!$this instanceof AccessTokenForRefresh){ |
|
42 | + if (!$this instanceof AccessTokenForRefresh) { |
|
43 | 43 | throw new ProviderException(sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires))); |
44 | 44 | } |
45 | 45 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | ) |
56 | 56 | ); |
57 | 57 | |
58 | - if(!$newToken->refreshToken){ |
|
58 | + if (!$newToken->refreshToken) { |
|
59 | 59 | $newToken->refreshToken = $refreshToken; |
60 | 60 | } |
61 | 61 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @property string $serviceName |
19 | 19 | * @property \chillerlan\OAuth\Storage\TokenStorageInterface $storage |
20 | 20 | */ |
21 | -trait CSRFTokenTrait{ |
|
21 | +trait CSRFTokenTrait { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @param string|null $state |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | */ |
29 | 29 | protected function checkState(string $state = null):OAuth2Interface{ |
30 | 30 | |
31 | - if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){ |
|
31 | + if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) { |
|
32 | 32 | throw new ProviderException('invalid state for '.$this->serviceName); |
33 | 33 | } |
34 | 34 | |
35 | 35 | $knownState = $this->storage->getCSRFState($this->serviceName); |
36 | 36 | |
37 | - if(!hash_equals($knownState, $state)){ |
|
37 | + if (!hash_equals($knownState, $state)) { |
|
38 | 38 | throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state); |
39 | 39 | } |
40 | 40 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | protected function setState(array $params):array { |
51 | 51 | |
52 | - if(!isset($params['state'])){ |
|
52 | + if (!isset($params['state'])) { |
|
53 | 53 | $params['state'] = sha1(random_bytes(256)); |
54 | 54 | } |
55 | 55 |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param \chillerlan\Traits\ContainerInterface|null $options |
35 | 35 | * @param \Psr\Log\LoggerInterface|null $logger |
36 | 36 | */ |
37 | - public function __construct(ContainerInterface $options = null, LoggerInterface $logger = null){ |
|
37 | + public function __construct(ContainerInterface $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):Token{ |
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 |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param \chillerlan\Traits\ContainerInterface $options |
91 | 91 | * @param \Psr\Log\LoggerInterface|null $logger |
92 | 92 | */ |
93 | - public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, LoggerInterface $logger = null){ |
|
93 | + public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $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 |
@@ -19,7 +19,7 @@ |
||
19 | 19 | * @property \Psr\Log\LoggerInterface $logger |
20 | 20 | * @method setLogger(\Psr\Log\LoggerInterface $logger) |
21 | 21 | */ |
22 | -interface TokenStorageInterface{ |
|
22 | +interface TokenStorageInterface { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @param string $service |
@@ -26,7 +26,7 @@ |
||
26 | 26 | * from \chillerlan\Traits\Classloader |
27 | 27 | * @method mixed loadClass(string $class, string $type = null, ...$params) |
28 | 28 | */ |
29 | -interface OAuthInterface{ |
|
29 | +interface OAuthInterface { |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @param array $params |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | ]; |
60 | 60 | |
61 | 61 | /** @var \chillerlan\Traits\ContainerInterface $options */ |
62 | -$options = new class($options_arr) extends OAuthOptions{ |
|
62 | +$options = new class($options_arr) extends OAuthOptions { |
|
63 | 63 | use DatabaseOptionsTrait, LogOptionsTrait; |
64 | 64 | }; |
65 | 65 | |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | $logger->addInstance(new ConsoleLog($options), 'console'); |
68 | 68 | |
69 | 69 | /** @var \chillerlan\HTTP\HTTPClientInterface $http */ |
70 | -$http = new class($options) extends HTTPClientAbstract{ |
|
70 | +$http = new class($options) extends HTTPClientAbstract { |
|
71 | 71 | |
72 | 72 | protected $client; |
73 | 73 | |
74 | - public function __construct(ContainerInterface $options){ |
|
74 | + public function __construct(ContainerInterface $options) { |
|
75 | 75 | parent::__construct($options); |
76 | 76 | $this->client = new TinyCurlClient($this->options, new Request($this->options)); |
77 | 77 | } |