@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | public function do(GuardInterface $guard) |
| 22 | 22 | { |
| 23 | - if (!$guard->allows('do')) { |
|
| 23 | + if (!$guard->allows('do')){ |
|
| 24 | 24 | throw new ControllerException("Unauthorized permission 'do'", ControllerException::FORBIDDEN); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function token(AuthContextInterface $authContext) |
| 31 | 31 | { |
| 32 | - if ($authContext->getToken() !== null) { |
|
| 32 | + if ($authContext->getToken() !== null){ |
|
| 33 | 33 | return $authContext->getToken()->getID(); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -18,10 +18,12 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | class AuthController |
| 20 | 20 | { |
| 21 | - public function do(GuardInterface $guard) |
|
| 21 | + public function do{ |
|
| 22 | + (GuardInterface $guard) |
|
| 22 | 23 | { |
| 23 | 24 | if (!$guard->allows('do')) { |
| 24 | 25 | throw new ControllerException("Unauthorized permission 'do'", ControllerException::FORBIDDEN); |
| 26 | + } |
|
| 25 | 27 | } |
| 26 | 28 | |
| 27 | 29 | return 'ok'; |
@@ -29,7 +31,8 @@ discard block |
||
| 29 | 31 | |
| 30 | 32 | public function token(AuthContextInterface $authContext) |
| 31 | 33 | { |
| 32 | - if ($authContext->getToken() !== null) { |
|
| 34 | + if ($authContext->getToken() !== null) |
|
| 35 | + { |
|
| 33 | 36 | return $authContext->getToken()->getID(); |
| 34 | 37 | } |
| 35 | 38 | |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | public function input(InputScope $i) |
| 50 | 50 | { |
| 51 | - return 'value: ' . $i->withPrefix('section')->getValue('query', 'value'); |
|
| 51 | + return 'value: '.$i->withPrefix('section')->getValue('query', 'value'); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | public function error(): void |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function load(string $id): ?TokenInterface |
| 45 | 45 | { |
| 46 | - if (strpos($id, ':') === false) { |
|
| 46 | + if (strpos($id, ':') === false){ |
|
| 47 | 47 | return null; |
| 48 | 48 | } |
| 49 | 49 | |
@@ -52,14 +52,14 @@ discard block |
||
| 52 | 52 | /** @var Token $token */ |
| 53 | 53 | $token = $this->orm->getRepository(Token::class)->findByPK($pk); |
| 54 | 54 | |
| 55 | - if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))) { |
|
| 55 | + if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))){ |
|
| 56 | 56 | // hijacked or deleted |
| 57 | 57 | return null; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $token->setSecretValue($hash); |
| 61 | 61 | |
| 62 | - if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) { |
|
| 62 | + if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()){ |
|
| 63 | 63 | $this->delete($token); |
| 64 | 64 | return null; |
| 65 | 65 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface |
| 74 | 74 | { |
| 75 | - try { |
|
| 75 | + try{ |
|
| 76 | 76 | $token = new Token( |
| 77 | 77 | $this->issueID(), |
| 78 | 78 | $this->randomHash(128), |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $this->em->persist($token)->run(); |
| 85 | 85 | |
| 86 | 86 | return $token; |
| 87 | - } catch (\Throwable $e) { |
|
| 87 | + }catch (\Throwable $e){ |
|
| 88 | 88 | throw new TokenStorageException('Unable to create token', $e->getCode(), $e); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | public function delete(TokenInterface $token): void |
| 96 | 96 | { |
| 97 | - try { |
|
| 97 | + try{ |
|
| 98 | 98 | $this->em->delete($token)->run(); |
| 99 | - } catch (\Throwable $e) { |
|
| 99 | + }catch (\Throwable $e){ |
|
| 100 | 100 | throw new TokenStorageException('Unable to delete token', $e->getCode(), $e); |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | $this->orm->getSource(Token::class)->getTable() |
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | - while ((clone $query)->where('id', $id)->count('id') !== 0) { |
|
| 118 | + while ((clone $query)->where('id', $id)->count('id') !== 0){ |
|
| 119 | 119 | $id = $this->randomHash(64); |
| 120 | 120 | } |
| 121 | 121 | |
@@ -43,7 +43,8 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function load(string $id): ?TokenInterface |
| 45 | 45 | { |
| 46 | - if (strpos($id, ':') === false) { |
|
| 46 | + if (strpos($id, ':') === false) |
|
| 47 | + { |
|
| 47 | 48 | return null; |
| 48 | 49 | } |
| 49 | 50 | |
@@ -52,14 +53,16 @@ discard block |
||
| 52 | 53 | /** @var Token $token */ |
| 53 | 54 | $token = $this->orm->getRepository(Token::class)->findByPK($pk); |
| 54 | 55 | |
| 55 | - if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))) { |
|
| 56 | + if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))) |
|
| 57 | + { |
|
| 56 | 58 | // hijacked or deleted |
| 57 | 59 | return null; |
| 58 | 60 | } |
| 59 | 61 | |
| 60 | 62 | $token->setSecretValue($hash); |
| 61 | 63 | |
| 62 | - if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) { |
|
| 64 | + if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) |
|
| 65 | + { |
|
| 63 | 66 | $this->delete($token); |
| 64 | 67 | return null; |
| 65 | 68 | } |
@@ -72,7 +75,8 @@ discard block |
||
| 72 | 75 | */ |
| 73 | 76 | public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface |
| 74 | 77 | { |
| 75 | - try { |
|
| 78 | + try |
|
| 79 | + { |
|
| 76 | 80 | $token = new Token( |
| 77 | 81 | $this->issueID(), |
| 78 | 82 | $this->randomHash(128), |
@@ -84,7 +88,9 @@ discard block |
||
| 84 | 88 | $this->em->persist($token)->run(); |
| 85 | 89 | |
| 86 | 90 | return $token; |
| 87 | - } catch (\Throwable $e) { |
|
| 91 | + } |
|
| 92 | + catch (\Throwable $e) |
|
| 93 | + { |
|
| 88 | 94 | throw new TokenStorageException('Unable to create token', $e->getCode(), $e); |
| 89 | 95 | } |
| 90 | 96 | } |
@@ -94,9 +100,12 @@ discard block |
||
| 94 | 100 | */ |
| 95 | 101 | public function delete(TokenInterface $token): void |
| 96 | 102 | { |
| 97 | - try { |
|
| 103 | + try |
|
| 104 | + { |
|
| 98 | 105 | $this->em->delete($token)->run(); |
| 99 | - } catch (\Throwable $e) { |
|
| 106 | + } |
|
| 107 | + catch (\Throwable $e) |
|
| 108 | + { |
|
| 100 | 109 | throw new TokenStorageException('Unable to delete token', $e->getCode(), $e); |
| 101 | 110 | } |
| 102 | 111 | } |
@@ -115,7 +124,8 @@ discard block |
||
| 115 | 124 | $this->orm->getSource(Token::class)->getTable() |
| 116 | 125 | ); |
| 117 | 126 | |
| 118 | - while ((clone $query)->where('id', $id)->count('id') !== 0) { |
|
| 127 | + while ((clone $query)->where('id', $id)->count('id') !== 0) |
|
| 128 | + { |
|
| 119 | 129 | $id = $this->randomHash(64); |
| 120 | 130 | } |
| 121 | 131 | |