-
Notifications
You must be signed in to change notification settings - Fork 46
/
callback.php
48 lines (38 loc) · 1.2 KB
/
callback.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use QuickBooksOnline\API\DataService\DataService;
session_start();
function processCode()
{
// Create SDK instance
$config = include('config.php');
$dataService = DataService::Configure(array(
'auth_mode' => 'oauth2',
'ClientID' => $config['client_id'],
'ClientSecret' => $config['client_secret'],
'RedirectURI' => $config['oauth_redirect_uri'],
'scope' => $config['oauth_scope'],
'baseUrl' => "development"
));
$OAuth2LoginHelper = $dataService->getOAuth2LoginHelper();
$parseUrl = parseAuthRedirectUrl(htmlspecialchars_decode($_SERVER['QUERY_STRING']));
/*
* Update the OAuth2Token
*/
$accessToken = $OAuth2LoginHelper->exchangeAuthorizationCodeForToken($parseUrl['code'], $parseUrl['realmId']);
$dataService->updateOAuth2Token($accessToken);
/*
* Setting the accessToken for session variable
*/
$_SESSION['sessionAccessToken'] = $accessToken;
}
function parseAuthRedirectUrl($url)
{
parse_str($url,$qsArray);
return array(
'code' => $qsArray['code'],
'realmId' => $qsArray['realmId']
);
}
$result = processCode();
?>