1 | <?php |
||
14 | final class Authentication |
||
15 | { |
||
16 | /** |
||
17 | * Function to create a Request object for obtaining a new token from the API |
||
18 | * |
||
19 | * @var callable |
||
20 | */ |
||
21 | private $getTokenRequestFunc; |
||
22 | |||
23 | /** |
||
24 | * Private constructor to safeguard undeclared functions |
||
25 | * |
||
26 | * @param callable $getTokenRequestFunc Function to create a Request object for obtaining a new token from the API |
||
27 | */ |
||
28 | private function __construct(callable $getTokenRequestFunc) |
||
32 | |||
33 | /** |
||
34 | * Creates a new instance of Authentication for Client Credentials grant type |
||
35 | * |
||
36 | * @param string $clientId The oauth client id |
||
37 | * @param string $clientSecret The oauth client secret |
||
38 | * @param string $refreshResource The refresh token resource of the API |
||
39 | * Only needed since apigee doesnt use the token resource that is in the oauth2 spec |
||
40 | * |
||
41 | * @return \DominionEnterprises\Api\Authentication |
||
42 | */ |
||
43 | public static function createClientCredentials( |
||
81 | |||
82 | /** |
||
83 | * Creates a new instance of Authentication for Owner Credentials grant type |
||
84 | * |
||
85 | * @param string $clientId The oauth client id |
||
86 | * @param string $clientSecret The oauth client secret |
||
87 | * @param string $username The oauth username |
||
88 | * @param string $password The oauth password |
||
89 | * @param string $refreshResource The refresh token resource of the API |
||
90 | * Only needed since apigee doesnt use the token resource that is in the oauth2 spec |
||
91 | * |
||
92 | * @return \DominionEnterprises\Api\Authentication |
||
93 | */ |
||
94 | public static function createOwnerCredentials( |
||
142 | |||
143 | /** |
||
144 | * Extracts an access token from the given API response |
||
145 | * |
||
146 | * @param ResponseInterface $response The API response containing the access token |
||
147 | * |
||
148 | * @return array Array containing the access token, refresh token and expires timestamp |
||
149 | */ |
||
150 | public static function parseTokenResponse(ResponseInterface $response) |
||
161 | |||
162 | /** |
||
163 | * Creates a Request object for obtaining a new token from the API |
||
164 | * |
||
165 | * @param string $baseUrl The base url of the API |
||
166 | * @param string $refreshToken The refresh token of the API |
||
167 | * |
||
168 | * @return \DominionEnterprises\Api\Request |
||
169 | */ |
||
170 | public function getTokenRequest($baseUrl, $refreshToken) |
||
177 | |||
178 | /** |
||
179 | * Build a refresh token request |
||
180 | * |
||
181 | * @param string $baseUrl API base url |
||
182 | * @param string $clientId The client id |
||
183 | * @param string $clientSecret The client secret |
||
184 | * @param string $refreshResource The refresh token resource of the API |
||
185 | * Only needed since apigee doesnt use the token resource that is in the oauth2 spec |
||
186 | * @param string $refreshToken The refresh token of the API |
||
187 | * |
||
188 | * @return \DominionEnterprises\Api\Request The built token refresh request |
||
189 | */ |
||
190 | private static function getRefreshTokenRequest( |
||
214 | } |
||
215 |