11<?php
22
3+ declare (strict_types=1 );
4+
35namespace BenjaminFavre \OAuthHttpClient \GrantType ;
46
57use Symfony \Contracts \HttpClient \Exception \TransportExceptionInterface ;
68use Symfony \Contracts \HttpClient \HttpClientInterface ;
79
810/**
911 * Implementation of the OAuth password grant type.
10- *
11- * @author Benjamin Favre <[email protected] > 1212 */
1313class PasswordGrantType implements GrantTypeInterface
1414{
1515 use TokensExtractor;
1616
17- /** @var HttpClientInterface */
18- private $ client ;
19- /** @var string */
20- private $ tokenUrl ;
21- /** @var string */
22- private $ username ;
23- /** @var string */
24- private $ password ;
25- /** @var ?string */
26- private $ clientId ;
27- /** @var ?string */
28- private $ clientSecret ;
17+ private HttpClientInterface $ client ;
18+
19+ private string $ tokenUrl ;
20+
21+ private string $ username ;
22+
23+ private string $ password ;
24+
25+ private ?string $ clientId ;
26+
27+ private ?string $ clientSecret ;
2928
3029 /**
3130 * @param HttpClientInterface $client A HTTP client to be used to communicate with the OAuth server.
3231 * @param string $tokenUrl The full URL of the token endpoint of the OAuth server.
3332 * @param string $username The OAuth user username.
3433 * @param string $password The OAuth user password.
35- * @param ? string $clientId The OAuth client ID.
36- * @param ? string $clientSecret The OAuth client secret.
34+ * @param string|null $clientId The OAuth client ID.
35+ * @param string|null $clientSecret The OAuth client secret.
3736 */
3837 public function __construct (
3938 HttpClientInterface $ client ,
4039 string $ tokenUrl ,
4140 string $ username ,
4241 string $ password ,
43- ? string $ clientId = null ,
44- ? string $ clientSecret = null
42+ string $ clientId = null ,
43+ string $ clientSecret = null ,
4544 ) {
4645 $ this ->client = $ client ;
4746 $ this ->tokenUrl = $ tokenUrl ;
@@ -52,9 +51,8 @@ public function __construct(
5251 }
5352
5453 /**
55- * { @inheritDoc}
54+ * @inheritDoc
5655 *
57- * @return Tokens
5856 * @throws TransportExceptionInterface
5957 */
6058 public function getTokens (): Tokens
@@ -64,7 +62,7 @@ public function getTokens(): Tokens
6462 'username ' => $ this ->username ,
6563 'password ' => $ this ->password ,
6664 ];
67-
65+
6866 if ($ this ->clientId !== null && $ this ->clientSecret !== null ) {
6967 $ parameters = array_merge ($ parameters , [
7068 'client_id ' => $ this ->clientId ,
@@ -78,4 +76,4 @@ public function getTokens(): Tokens
7876
7977 return $ this ->extractTokens ($ response );
8078 }
81- }
79+ }
0 commit comments