Skip to content
Permalink
master
Switch branches/tags
Go to file
@hlu2
Latest commit 2a7bafe Apr 13, 2018 History
1 contributor

Users who have contributed to this file

<?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($_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();
?>