To enable a secure connection between your online store and the Duty and Taxes Calculator, you must authenticate your website with our servers so that they can verify your identity. This authentication step is a server to server call that should be made from your webserver to the GFS identity server in order to return an access token that is passed to the API call. This process uses the industry standard Oauth2 Client Credentials grant type. It is well supported in all common languages and frameworks deployed in eCommerce solutions.
Your welcome email will provide you with a Client ID and Secret which will be required to complete authentication.
Below you will find an example of the code that will help you obtain this access token.
The following code demonstrates authentication with the GFS Identity endpoint using PHP. Please note that this code uses CURL, rather than the Zend library, to show the simplest authentication possible, while remaining agnostic of PHP add-ins.
$endpoint = "https://identity.justshoutgfs.com/connect/token";
$params = array(
"client_id" => "CLIENT_ID",
"client_secret" => "CLIENT_SECRET",
"grant_type" => "client_credentials",
"scope" => "landed-cost:read");
$curl = curl_init($endpoint);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER,'Content-Type: application/x-www-form-urlencoded');
// Remove comment if you have a setup that causes ssl validation to fail
//curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$postData = "";
//This is needed to properly form post the credentials object
foreach($params as $k => $v) {
$postData .= $k . '='.urlencode($v).'&';
}
$postData = rtrim($postData, '&');
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
echo "Performing Request...";
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// evaluate for success response
if ($status != 200) {
throw new Exception("Error: call to URL $endpoint failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl) . "\n");
}
curl_close($curl);
return $json_response;
The example below shows you how to obtain an access token using .NET, the open source Identity Server 3, and Identity Model libraries. These can be installed using NuGet.
var client = new TokenClient(
@"https://identity.justshoutgfs.com/connect/token",
"CLIENT_ID",
"CLIENT_SECRET");
var resp = client.RequestClientCredentialsAsync("landed-cost:read").Result;
if(!resp.IsError)
{
// Token is the JWT generated to be used by the D&T
token = resp.AccessToken;
}
else
{
// Handle authentication error
}