forked from sizeid/oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientApi.php
34 lines (26 loc) · 900 Bytes
/
clientApi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require __DIR__ . '/bootstrap.php';
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Message\Request;
use SizeID\OAuth2\ClientApi;
// Initialize communication object.
// For full list of parameters see UserApi::__construct().
// All parameters could be replaced with custom value or implementation.
$clientApi = new ClientApi(
CLIENT_ID,
CLIENT_SECRET
);
try {
// create request to 'client' endpoint using 'get' method
$request = new Request('get', 'client');
// send request
// if needed acquire access token using client credentials method
$response = $clientApi->send($request);
// get response body
$rawBody = $response->getBody()->getContents();
} catch (BadResponseException $ex) {
// something went wrong - http response code is not 2xx
$rawBody = $ex->getResponse()->getBody()->getContents();
}
// dump request content
dump(json_decode($rawBody, true));