Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Wrapper libraries >

SHA2 Prep with PHP

Started by Ronan Quirke (Community Manager) -   in Wrapper libraries

So, how do you check that your PHP application works with SHA2 then?

It is pretty easy actually - examples for two popular libraries are included below.

XeroOAuth-PHP
For the XeroOAuth-PHP library, checking SHA2 validity is pretty easy - you just need to override the library default urls for the API in your config settings.

Here is what needs to be changed in the $signatures array within the config settings for Private/Public applications:
$signatures = array(
'consumer_key' => 'YOURCONSUMERKEY',
'shared_secret' => 'YOURCONSUMERSECRET',
// Override default settings with SHA2 URLs
'xero_url' => 'https://sha2-api.xero.com/',
'site' => 'https://sha2-api.xero.com',
'authorize_url' => 'https://sha2-api.xero.com/oauth/Authorize',

// API versions
'core_version'=> '2.0',
'payroll_version'=> '1.0',
'file_version' => '1.0');


You can view a better formatted example in a Github gist.

Here is what needs to be changed in the $signatures array within the config settings for Partner applications:
$signatures = array(
'consumer_key' => 'YOURCONSUMERKEY',
'shared_secret' => 'YOURCONSUMERSECRET',
// Override default settings with SHA2 URLs
'xero_url' => 'https://sha2-api-partner.network.xero.com/',
'site' => 'https://sha2-api-partner.network.xero.com',
'authorize_url' => 'https://sha2-api.xero.com/oauth/Authorize',

// API versions
'core_version'=> '2.0',
'payroll_version'=> '1.0',
'file_version' => '1.0');


XeroPHP
For the XeroPHP library, checking SHA2 validity is also pretty easy - you just need to add some extra config settings.

$config = array(
'xero' => array(
'site' => 'https://sha2-api.xero.com',
'base_url' => 'https://sha2-api.xero.com'
),

'oauth' => array(
'callback' => 'http://localhost/',
'consumer_key' => 'k',
'consumer_secret' => 's',
'rsa_private_key' => 'file://certs/privatekey.pem'
)
);


The above example URLs are for public and private applications, but partner applications should work the same way.