Skip to content
This repository was archived by the owner on May 29, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

$country = $_GET['country'];

switch($country) {
case "CA": $token_endpoint = $ca_token_endpoint; break;
case "US": $token_endpoint = $us_token_endpoint; break;
case "IE": case "GB": $token_endpoint = $uki_token_endpoint; break;
default: $token_endpoint = $uki_token_endpoint; break;
if ( isset( $endpoints['token'][$country] ) )
$token_endpoint = $endpoints['token'][$country] ;
else {
echo "Country endpoints not defined" ;
exit ;
}

$sageone_client = new SageoneClient($client_id, $client_secret, $callback_url, $auth_endpoint, $token_endpoint, $scope);
$sageone_client = new SageoneClient($client_id, $client_secret, $callback_url, $endpoints['auth'], $token_endpoint, $scope);

/* Exchange the authorisation code for an access_token */
$response = $sageone_client->getAccessToken($_GET['code']);
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
include 'sageone_client.php';
include 'sageone_constants.php';

$sageone_client = new SageoneClient($client_id, $client_secret, $callback_url, $auth_endpoint, $token_endpoint, $scope);
$sageone_client = new SageoneClient($client_id, $client_secret, $callback_url, $endpoints['auth'], null, $scope);

/* get the redirect url for authorisation */
$redirect_url = $sageone_client->authRedirect();
Expand Down
41 changes: 28 additions & 13 deletions sageone_constants.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
<?php
$client_id = 'YOUR_CLIENT_ID';
$client_secret = 'YOUR_CLIENT_SECRET';
$signing_secret = 'YOUR_SIGNING_SECRET';
$apim_subscription_key = 'YOUR APIM SUBSCRIPTION_KEY';
$callback_url = 'http://localhost:8080/callback.php';
$scope = 'full_access';
$auth_endpoint = 'http://www.sageone.com/oauth2/auth';
$us_token_endpoint = 'http://mysageone.na.sageone.com/oauth2/token';
$ca_token_endpoint = 'http://mysageone.ca.sageone.com/oauth2/token';
$uki_token_endpoint = 'http://app.sageone.com/oauth2/token';
$us_base_endpoint = 'https://api.columbus.sage.com/us/sageone/';
$ca_base_endpoint = 'https://api.columbus.sage.com/ca/sageone/';
$uki_base_endpoint = 'https://api.columbus.sage.com/uki/sageone/';

$client_id = 'YOUR_CLIENT_ID';
$client_secret = 'YOUR_CLIENT_SECRET';
$signing_secret = 'YOUR_SIGNING_SECRET';
$apim_subscription_key = 'YOUR APIM SUBSCRIPTION_KEY';
$callback_url = 'http://localhost:8080/callback.php';
$scope = 'full_access';
$endpoints = [
'auth' => 'https://www.sageone.com/oauth2/auth/central',
'token' => [
'CA' => 'https://mysageone.ca.sageone.com/oauth2/token',
'DE' => 'https://oauth.eu.sageone.com/token',
'ES' => 'https://oauth.eu.sageone.com/token',
'FR' => 'https://oauth.eu.sageone.com/token',
'GB' => 'https://app.sageone.com/oauth2/token',
'IE' => 'https://app.sageone.com/oauth2/token',
'US' => 'https://mysageone.na.sageone.com/oauth2/token'
],
'base' => [
'CA' => 'https://api.columbus.sage.com/ca/sageone/',
'DE' => 'https://api.columbus.sage.com/de/sageone/',
'ES' => 'https://api.columbus.sage.com/es/sageone/',
'FR' => 'https://api.columbus.sage.com/fr/sageone/',
'GB' => 'https://api.columbus.sage.com/uki/sageone/',
'IE' => 'https://api.columbus.sage.com/uki/sageone/',
'US' => 'https://api.columbus.sage.com/us/sageone/'
]
];

?>
31 changes: 11 additions & 20 deletions sageone_response.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
<!DOCTYPE html>
<?php

include 'sageone_constants.php';
include 'sageone_signer.php';
include 'sageone_client.php';

$country = $_GET['country'] ?: $_POST['country'];

switch($country) {
case "CA":
$base_endpoint = $ca_base_endpoint;
$token_endpoint = $ca_token_endpoint;
break;
case "US":
$base_endpoint = $us_base_endpoint;
$token_endpoint = $us_token_endpoint;
break;
case "IE": case "GB":
$base_endpoint = $uki_base_endpoint;
$token_endpoint = $uki_token_endpoint;
break;
default:
$base_endpoint = $uki_base_endpoint;
$token_endpoint = $uki_token_endpoint;
break;
};

$sageone_client = new SageoneClient($client_id, $client_secret, $callback_url, $auth_endpoint, $token_endpoint, $scope);
if ( isset( $endpoints['base'][$country] ) && isset( $endpoints['token'][$country] ) ) {
$base_endpoint = $endpoints['base'][$country] ;
$token_endpoint = $endpoints['token'][$country] ;
}
else {
echo "Country endpoints not defined" ;
exit ;
}

$sageone_client = new SageoneClient($client_id, $client_secret, $callback_url, $endpoints['auth'], $token_endpoint, $scope);
$nonce = bin2hex(openssl_random_pseudo_bytes(32));
$header = array("Accept: *.*",
"Content-Type: application/json",
Expand Down