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 Only needed since apigee doesnt use the |
||
39 | * token resource that is in the oauth2 spec |
||
40 | * @param string $tokenResource The access token resource of the API |
||
41 | * |
||
42 | * @return Authentication |
||
43 | */ |
||
44 | public static function createClientCredentials( |
||
80 | |||
81 | /** |
||
82 | * Creates a new instance of Authentication for Owner Credentials grant type |
||
83 | * |
||
84 | * @param string $clientId The oauth client id |
||
85 | * @param string $clientSecret The oauth client secret |
||
86 | * @param string $username The oauth username |
||
87 | * @param string $password The oauth password |
||
88 | * @param string $refreshResource The refresh token resource of the API. Only needed since apigee doesnt use the |
||
89 | * token resource that is in the oauth2 spec |
||
90 | * @param string $tokenResource The access token resource of the API |
||
91 | * |
||
92 | * @return Authentication |
||
93 | */ |
||
94 | public static function createOwnerCredentials( |
||
140 | |||
141 | /** |
||
142 | * Extracts an access token from the given API response |
||
143 | * |
||
144 | * @param ResponseInterface $response The API response containing the access token |
||
145 | * |
||
146 | * @return array Array containing the access token, refresh token and expires timestamp |
||
147 | */ |
||
148 | public static function parseTokenResponse(ResponseInterface $response) |
||
163 | |||
164 | /** |
||
165 | * Creates a Request object for obtaining a new token from the API |
||
166 | * |
||
167 | * @param string $baseUrl The base url of the API |
||
168 | * @param string|null $refreshToken The refresh token of the API |
||
169 | * |
||
170 | * @return RequestInterface |
||
171 | */ |
||
172 | public function getTokenRequest(string $baseUrl, string $refreshToken = null) : RequestInterface |
||
176 | |||
177 | /** |
||
178 | * Build a refresh token request |
||
179 | * |
||
180 | * @param string $baseUrl API base url |
||
181 | * @param string $clientId The client id |
||
182 | * @param string $clientSecret The client secret |
||
183 | * @param string $refreshResource The refresh token resource of the API |
||
184 | * Only needed since apigee doesnt use the token resource that is in the oauth2 spec |
||
185 | * @param string $refreshToken The refresh token of the API |
||
186 | * |
||
187 | * @return RequestInterface The built token refresh request |
||
188 | */ |
||
189 | private static function getRefreshTokenRequest( |
||
213 | } |
||
214 |