Spektrix API v3 Authentication wp_remote_get()

Question

I have a need to authenticate a GET request to Spektrix. The API requests that require authentication need an API Login Name and a API Secret Key.

The API Secret Key needs to be base-64 encoded, and must be decoded before use in the HMAC step of the Authentication process.

They have given me the following as an example:

GET api/v3/customers/123
Host: system.spektrix.com
Date: Mon, 26 Mar 2007 19:37:58 +0000
Authorization: SpektrixAPI3 TestLogin:frJIUN8DYpKDtOLCwo//yllqDzg=

Constructing the Authorization Header

Authorization = "SpektrixAPI3 " + LoginName + ":" + Signature;

Signature = BASE-64-ENCODE( HMAC-SHA1( BASE-64-DECODE(SecretKey), UTF-8( StringToSign ) ) );

StringToSign = HTTP-Method 
            + "n" + HTTP-Uri
            + "n" + HTTP-Date
            + [ "n" , BodyStringToSign ];

BodyStringToSign = BASE-64( MD5( UTF-8( body ) ) )

My question is:

How do I construct this in PHP using wp_remote_get()?

Any help would be really appreciated.

Additional Info:

I have the current function in a Class which works for non authenticated requests

function get_spektrix_data($obj_url)
{

    $args = array(
        'timeout'       => 120,
        'sslcert'       => self::get_path_to_cert(),
        'sslkey'        => self::get_path_to_key(),
    );

    $request = wp_remote_get( $obj_url, $args );
    if( is_wp_error( $request ) ) {
        return false; // Bail early
    }
    $json = wp_remote_retrieve_body( $request );
    return $json;
}
0
, Martin Greenwood 3 years 2020-03-13T04:52:05-05:00 0 Answers 137 views 0

Leave an answer

Browse
Browse