@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | 143 | * @param string $name |
| 144 | - * @return mixed |
|
| 144 | + * @return boolean |
|
| 145 | 145 | * @throws \Exception |
| 146 | 146 | */ |
| 147 | 147 | public function getConfig(string $name) |
@@ -161,6 +161,9 @@ discard block |
||
| 161 | 161 | return $this->grantTypes[$uri] ?? null; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | + /** |
|
| 165 | + * @return \OAuth2\Storages\AuthorizationCodeStorageInterface |
|
| 166 | + */ |
|
| 164 | 167 | public function getStorage(string $name) |
| 165 | 168 | { |
| 166 | 169 | return $this->storages[$name]; |
@@ -18,7 +18,6 @@ |
||
| 18 | 18 | use OAuth2\Storage\AuthorizationCodeStorage; |
| 19 | 19 | use OAuth2\Storage\ClientStorage; |
| 20 | 20 | use OAuth2\Role\Client\RegisteredClient; |
| 21 | -use OAuth2\Role\Client\Type\ClientPassword; |
|
| 22 | 21 | use Psr\Http\Message\ServerRequestInterface; |
| 23 | 22 | |
| 24 | 23 | class Server |
@@ -90,15 +90,15 @@ discard block |
||
| 90 | 90 | { |
| 91 | 91 | foreach (self::STORAGES as $name => $class) { |
| 92 | 92 | if (!isset($storages[$name])) { |
| 93 | - throw new \Exception('Missing storage "' . $name . '"'); |
|
| 93 | + throw new \Exception('Missing storage "'.$name.'"'); |
|
| 94 | 94 | } |
| 95 | 95 | if (!is_a($storages[$name], $class)) { |
| 96 | - throw new \Exception('Storage "' . $name . '" must implement interface "' . $class . '"'); |
|
| 96 | + throw new \Exception('Storage "'.$name.'" must implement interface "'.$class.'"'); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | if (array_diff(self::MINIMAL_CONFIG, array_keys($config))) { |
| 101 | - throw new \Exception('Missing minimal configuration. Required : ' . implode(', ', self::MINIMAL_CONFIG)); |
|
| 101 | + throw new \Exception('Missing minimal configuration. Required : '.implode(', ', self::MINIMAL_CONFIG)); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $this->config = array_merge(self::DEFAULT_CONFIG, $config); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | public function getConfig(string $name) |
| 148 | 148 | { |
| 149 | - if(!isset($this->config[$name])) { |
|
| 149 | + if (!isset($this->config[$name])) { |
|
| 150 | 150 | throw new \Exception('Config with name "'.$name.'" not found'); |
| 151 | 151 | } |
| 152 | 152 | return $this->config[$name]; |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | public function authenticate(ServerRequestInterface $request) |
| 393 | 393 | { |
| 394 | 394 | $this->client = $this->guard->authenticate($request); |
| 395 | - return (bool)$this->client; |
|
| 395 | + return (bool) $this->client; |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -11,19 +11,11 @@ |
||
| 11 | 11 | use GuzzleHttp\Psr7\Uri; |
| 12 | 12 | use OAuth2\Credential\AccessToken; |
| 13 | 13 | use OAuth2\Credential\RefreshToken; |
| 14 | -use OAuth2\Credential\TokenType\BearerToken; |
|
| 15 | -use OAuth2\Endpoint\Config; |
|
| 16 | 14 | use OAuth2\Endpoint\Server\Messages\AccessToken\AccessTokenRequest; |
| 17 | 15 | use OAuth2\Endpoint\Server\Messages\AccessToken\AccessTokenResponse; |
| 18 | -use OAuth2\Endpoint\Server\Messages\Authorization\AuthorizationRequest; |
|
| 19 | 16 | use OAuth2\Endpoint\Server\Messages\AccessToken\ErrorResponse; |
| 20 | -use OAuth2\GrantType\AuthorizationCode; |
|
| 21 | 17 | use OAuth2\GrantType\InvalidGrantType; |
| 22 | -use OAuth2\Storage\ClientStorage; |
|
| 23 | 18 | use OAuth2\Role\Client; |
| 24 | -use OAuth2\Role\Client\RegisteredClient; |
|
| 25 | -use OAuth2\Role\Client\Type\ClientPassword; |
|
| 26 | -use Psr\Http\Message\ServerRequestInterface; |
|
| 27 | 19 | |
| 28 | 20 | |
| 29 | 21 | /** |
@@ -167,7 +167,7 @@ |
||
| 167 | 167 | try { |
| 168 | 168 | $redirectUri = $grantType->grant($request, $client); |
| 169 | 169 | } |
| 170 | - catch(InvalidGrantType $e) { |
|
| 170 | + catch (InvalidGrantType $e) { |
|
| 171 | 171 | return new ErrorResponse('invalid_grant', $e->getErrorDescription(), $e->getErrorUri()); |
| 172 | 172 | } |
| 173 | 173 | |
@@ -166,8 +166,7 @@ |
||
| 166 | 166 | |
| 167 | 167 | try { |
| 168 | 168 | $redirectUri = $grantType->grant($request, $client); |
| 169 | - } |
|
| 170 | - catch(InvalidGrantType $e) { |
|
| 169 | + } catch(InvalidGrantType $e) { |
|
| 171 | 170 | return new ErrorResponse('invalid_grant', $e->getErrorDescription(), $e->getErrorUri()); |
| 172 | 171 | } |
| 173 | 172 | |
@@ -8,15 +8,10 @@ |
||
| 8 | 8 | |
| 9 | 9 | namespace OAuth2\GrantType; |
| 10 | 10 | use OAuth2\Endpoint\Server\Messages\AccessToken\AccessTokenRequest; |
| 11 | -use OAuth2\Endpoint\Server\Messages\AccessToken\ErrorResponse; |
|
| 12 | 11 | use OAuth2\Endpoint\Server\Messages\Authorization\AuthorizationRequest; |
| 13 | 12 | use OAuth2\Endpoint\Server\Messages\Authorization\AuthorizationResponse; |
| 14 | -use OAuth2\Endpoint\Server\Server; |
|
| 15 | -use OAuth2\Role\Client; |
|
| 16 | 13 | use OAuth2\Role\Client\RegisteredClient; |
| 17 | -use OAuth2\Storage\AuthorizationCodeStorage; |
|
| 18 | 14 | use OAuth2\Storages\AuthorizationCodeStorageInterface; |
| 19 | -use Psr\Http\Message\ServerRequestInterface; |
|
| 20 | 15 | |
| 21 | 16 | /** |
| 22 | 17 | * Class AuthorizationCode |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @var AuthenticatorInterface $authenticator |
| 31 | 31 | */ |
| 32 | 32 | foreach ($this->authenticators as $authenticator) { |
| 33 | - if($authenticator->requireAuthentication($client)) { |
|
| 33 | + if ($authenticator->requireAuthentication($client)) { |
|
| 34 | 34 | return true; |
| 35 | 35 | } |
| 36 | 36 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @var AuthenticatorInterface $authenticator |
| 44 | 44 | */ |
| 45 | 45 | foreach ($this->authenticators as $authenticator) { |
| 46 | - if($client = $authenticator->authenticate($request)) { |
|
| 46 | + if ($client = $authenticator->authenticate($request)) { |
|
| 47 | 47 | return $client; |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -36,25 +36,25 @@ |
||
| 36 | 36 | public function __construct(string $error, ?string $errorDescription = null, ?string $errorUri = null, int $status = 400, array $headers = []) |
| 37 | 37 | { |
| 38 | 38 | if ($this->containsNotAsciiChar($error)) { |
| 39 | - throw new \Exception('Malformed error type. Expect ascii string. Got : ' . $error); |
|
| 39 | + throw new \Exception('Malformed error type. Expect ascii string. Got : '.$error); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | if (!in_array($error, self::errors)) { |
| 43 | - throw new \Exception('Unexpected error type. Expect one of : ' . implode(', ', self::errors)); |
|
| 43 | + throw new \Exception('Unexpected error type. Expect one of : '.implode(', ', self::errors)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $data = ['error' => $error]; |
| 47 | 47 | |
| 48 | 48 | if ($errorDescription) { |
| 49 | 49 | if ($this->containsNotAsciiChar($errorDescription)) { |
| 50 | - throw new \Exception('Malformed error description. Expect ascii string. Got : ' . $errorDescription); |
|
| 50 | + throw new \Exception('Malformed error description. Expect ascii string. Got : '.$errorDescription); |
|
| 51 | 51 | } |
| 52 | 52 | $data['error_description'] = $errorDescription; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | if ($errorUri) { |
| 56 | 56 | if ($this->containsNotAsciiChar($errorUri)) { |
| 57 | - throw new \Exception('Malformed error uri. Expect ascii string. Got : ' . $errorUri); |
|
| 57 | + throw new \Exception('Malformed error uri. Expect ascii string. Got : '.$errorUri); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $data['error_uri'] = $errorDescription; |
@@ -10,8 +10,6 @@ |
||
| 10 | 10 | |
| 11 | 11 | |
| 12 | 12 | use GuzzleHttp\Psr7\Response; |
| 13 | -use GuzzleHttp\Psr7\Uri; |
|
| 14 | -use Psr\Http\Message\UriInterface; |
|
| 15 | 13 | |
| 16 | 14 | class ErrorResponse extends Response |
| 17 | 15 | { |
@@ -36,18 +36,18 @@ discard block |
||
| 36 | 36 | public function __construct(UriInterface $redirectUri, string $error, ?string $errorDescription = null, ?string $errorUri = null) |
| 37 | 37 | { |
| 38 | 38 | if ($this->containsNotAsciiChar($error)) { |
| 39 | - throw new \Exception('Malformed error type. Expect ascii string. Got : ' . $error); |
|
| 39 | + throw new \Exception('Malformed error type. Expect ascii string. Got : '.$error); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | if (!in_array($error, self::errors)) { |
| 43 | - throw new \Exception('Unexpected error type. Expect one of : ' . implode(', ', self::errors)); |
|
| 43 | + throw new \Exception('Unexpected error type. Expect one of : '.implode(', ', self::errors)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $redirectUri = Uri::withQueryValue($redirectUri, 'error', $error); |
| 47 | 47 | |
| 48 | 48 | if ($errorDescription) { |
| 49 | 49 | if ($this->containsNotAsciiChar($errorDescription)) { |
| 50 | - throw new \Exception('Malformed error description. Expect ascii string. Got : ' . $errorDescription); |
|
| 50 | + throw new \Exception('Malformed error description. Expect ascii string. Got : '.$errorDescription); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $redirectUri = Uri::withQueryValue($redirectUri, 'error_description', $errorDescription); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | if ($errorUri) { |
| 57 | 57 | if ($this->containsNotAsciiChar($errorUri)) { |
| 58 | - throw new \Exception('Malformed error uri. Expect ascii string. Got : ' . $errorUri); |
|
| 58 | + throw new \Exception('Malformed error uri. Expect ascii string. Got : '.$errorUri); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $redirectUri = Uri::withQueryValue($redirectUri, 'error_uri', $errorUri); |
@@ -96,11 +96,11 @@ |
||
| 96 | 96 | * @throws \Exception |
| 97 | 97 | */ |
| 98 | 98 | public function validate() { |
| 99 | - if(!$this->responseType) { |
|
| 99 | + if (!$this->responseType) { |
|
| 100 | 100 | throw new \Exception('Missing response_type parameter'); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - if(!$this->clientId) { |
|
| 103 | + if (!$this->clientId) { |
|
| 104 | 104 | throw new \Exception('Missing client_id parameter'); |
| 105 | 105 | } |
| 106 | 106 | return true; |
@@ -94,10 +94,10 @@ |
||
| 94 | 94 | */ |
| 95 | 95 | static public function createFromServerRequest(ServerRequestInterface $request) |
| 96 | 96 | { |
| 97 | - if(!isset($request->getParsedBody()['grant_type'])) { |
|
| 97 | + if (!isset($request->getParsedBody()['grant_type'])) { |
|
| 98 | 98 | throw new \Exception('Missing a required parameter : grant_type'); |
| 99 | 99 | } |
| 100 | - if(!isset($request->getParsedBody()['code'])) { |
|
| 100 | + if (!isset($request->getParsedBody()['code'])) { |
|
| 101 | 101 | throw new \Exception('Missing a required parameter : code'); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -37,18 +37,18 @@ discard block |
||
| 37 | 37 | ?string $errorUri = null, ?string $state = null) |
| 38 | 38 | { |
| 39 | 39 | if ($this->containsNotAsciiChar($error)) { |
| 40 | - throw new \Exception('Malformed error type. Expect ascii string. Got : ' . $error); |
|
| 40 | + throw new \Exception('Malformed error type. Expect ascii string. Got : '.$error); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | if (!in_array($error, self::errors)) { |
| 44 | - throw new \Exception('Unexpected error type. Expect one of : ' . implode(', ', self::errors)); |
|
| 44 | + throw new \Exception('Unexpected error type. Expect one of : '.implode(', ', self::errors)); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | $redirectUri = Uri::withQueryValue($redirectUri, 'error', $error); |
| 48 | 48 | |
| 49 | 49 | if ($errorDescription) { |
| 50 | 50 | if ($this->containsNotAsciiChar($errorDescription)) { |
| 51 | - throw new \Exception('Malformed error description. Expect ascii string. Got : ' . $errorDescription); |
|
| 51 | + throw new \Exception('Malformed error description. Expect ascii string. Got : '.$errorDescription); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | $redirectUri = Uri::withQueryValue($redirectUri, 'error_description', $errorDescription); |
@@ -56,13 +56,13 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | if ($errorUri) { |
| 58 | 58 | if ($this->containsNotAsciiChar($errorUri)) { |
| 59 | - throw new \Exception('Malformed error uri. Expect ascii string. Got : ' . $errorUri); |
|
| 59 | + throw new \Exception('Malformed error uri. Expect ascii string. Got : '.$errorUri); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | $redirectUri = Uri::withQueryValue($redirectUri, 'error_uri', $errorUri); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if($state) { |
|
| 65 | + if ($state) { |
|
| 66 | 66 | $redirectUri = Uri::withQueryValue($redirectUri, 'state', $state); |
| 67 | 67 | } |
| 68 | 68 | |