Skip to content

Commit

Permalink
Add static getAuthSignature()
Browse files Browse the repository at this point in the history
  • Loading branch information
yidas committed Aug 12, 2020
1 parent 4db8869 commit d28776e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/linePay/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ function __construct($optParams)
return $this;
}

/**
* Get LINE Pay signature for authentication
*
* @param string $channelSecret
* @param string $uri
* @param string $queryOrBody
* @param string $nonce
* @return string
*/
static public function getAuthSignature($channelSecret, $uri, $queryOrBody, $nonce)
{
$authMacText = $channelSecret . $uri . $queryOrBody . $nonce;
return base64_encode(hash_hmac('sha256', $authMacText, $channelSecret, true));
}

/**
* Get Request object
*
Expand Down Expand Up @@ -174,8 +189,7 @@ protected function requestHandler($version, $method, $uri, $queryParams=null, $b
// V3 API Authentication
$authNonce = date('c') . uniqid('-'); // ISO 8601 date + UUID 1
$authParams = ($method=='GET' && $queryParams) ? $queryString : (($bodyParams) ? $body : null);
$authMacText = $this->channelSecret . $uri . $authParams . $authNonce;
$headers['X-LINE-Authorization'] = base64_encode(hash_hmac('sha256', $authMacText, $this->channelSecret, true));
$headers['X-LINE-Authorization'] = self::getAuthSignature($this->channelSecret, $uri, $authParams, $authNonce);
$headers['X-LINE-Authorization-Nonce'] = $authNonce;
break;
}
Expand Down

0 comments on commit d28776e

Please sign in to comment.