Generating Signatures for the Authentication Header in PHP - Paypal

笑着哭i 提交于 2020-01-13 06:41:05

问题


Having recently finished the process of having created the script that retrieves permissions from a account holder I now find that I have to convert the retrieved access token and token secret (from the GetAccessToken response) to the API signature in order to create a X-PAYPAL-AUTHORIZATION header.

The X-PAYPAL-AUTHORIZATION header contains:

  • A timestamp
  • The access token from the GetAccessToken response
  • A signature generated from the following information:
    • Your API username
    • Your API password
    • The access token from the GetAccessToken response
    • The token secret from the GetAccessToken response
    • The endpoint for the PayPal API operation's request, such as https://api.paypal.com/nvp
    • HTTPS delivery method, such as POST
    • Request parameters associated with the request

The problem is I can't find how to generate the signature. There are no guides in PHP (JAVA and Ruby).

I did however note the line in the guide I followed (first link) to retrieve the permissions:

PayPal provides SDKs that you can use to generate authentication header signatures for Java, PHP, and .NET. When you use the SDK, you will get two values, such as the following:

But what followed was the JAVA guide and I could not find anything amongth Paypal's SDKs.

Any help would be greatly appreciated!


回答1:


This documentation actually cuts out the function from their PHP SDK that should do it for you.

private function generateAuthString($apiCred, $accessToken, $tokenSecret, $endpoint)
{
$callerUid = $apiCred->getUserName();
$callerPswd = $apiCred->getPassword();
$auth = new AuthSignature();
$response = $auth->genSign($callerUid,$callerPswd,$accessToken,$tokenSecret,'POST',$endpoint);
$authString =
"token=".$accessToken.
",signature=".$response['oauth_signature'].
",timestamp=".$response['oauth_timestamp'];
return $authString;
}


来源:https://stackoverflow.com/questions/21650307/generating-signatures-for-the-authentication-header-in-php-paypal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!