OAuthOAuth1SignatureSignature

The Gravity Forms Salesforce Add-On OAuth OAuth1 Signature class.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/src/OAuth/OAuth1/Signature/Signature.php  
  1. class Signature implements SignatureInterface 
  2. /** 
  3. * @var Credentials 
  4. */ 
  5. protected $credentials; 
  6.  
  7. /** 
  8. * @var string 
  9. */ 
  10. protected $algorithm; 
  11.  
  12. /** 
  13. * @var string 
  14. */ 
  15. protected $tokenSecret = null; 
  16.  
  17. /** 
  18. * @param CredentialsInterface $credentials 
  19. */ 
  20. public function __construct(CredentialsInterface $credentials) 
  21. $this->credentials = $credentials; 
  22.  
  23. /** 
  24. * @param string $algorithm 
  25. */ 
  26. public function setHashingAlgorithm($algorithm) 
  27. $this->algorithm = $algorithm; 
  28.  
  29. /** 
  30. * @param string $token 
  31. */ 
  32. public function setTokenSecret($token) 
  33. $this->tokenSecret = $token; 
  34.  
  35. /** 
  36. * @param UriInterface $uri 
  37. * @param array $params 
  38. * @param string $method 
  39. * @return string 
  40. */ 
  41. public function getSignature(UriInterface $uri, array $params, $method = 'POST') 
  42. parse_str($uri->getQuery(), $queryStringData); 
  43.  
  44. foreach (array_merge($queryStringData, $params) as $key => $value) { 
  45. $signatureData[rawurlencode($key)] = rawurlencode($value); 
  46.  
  47. ksort($signatureData); 
  48.  
  49. // determine base uri 
  50. $baseUri = $uri->getScheme() . '://' . $uri->getRawAuthority(); 
  51.  
  52. if ('/' === $uri->getPath()) { 
  53. $baseUri .= $uri->hasExplicitTrailingHostSlash() ? '/' : ''; 
  54. } else { 
  55. $baseUri .= $uri->getPath(); 
  56.  
  57. $baseString = strtoupper($method) . '&'; 
  58. $baseString .= rawurlencode($baseUri) . '&'; 
  59. $baseString .= rawurlencode($this->buildSignatureDataString($signatureData)); 
  60.  
  61. return base64_encode($this->hash($baseString)); 
  62.  
  63. /** 
  64. * @param array $signatureData 
  65. * @return string 
  66. */ 
  67. protected function buildSignatureDataString(array $signatureData) 
  68. $signatureString = ''; 
  69. $delimiter = ''; 
  70. foreach ($signatureData as $key => $value) { 
  71. $signatureString .= $delimiter . $key . '=' . $value; 
  72.  
  73. $delimiter = '&'; 
  74.  
  75. return $signatureString; 
  76.  
  77. /** 
  78. * @return string 
  79. */ 
  80. protected function getSigningKey() 
  81. $signingKey = rawurlencode($this->credentials->getConsumerSecret()) . '&'; 
  82. if ($this->tokenSecret !== null) { 
  83. $signingKey .= rawurlencode($this->tokenSecret); 
  84.  
  85. return $signingKey; 
  86.  
  87. /** 
  88. * @param string $data 
  89. * @return string 
  90. * @throws UnsupportedHashAlgorithmException 
  91. */ 
  92. protected function hash($data) 
  93. switch (strtoupper($this->algorithm)) { 
  94. case 'HMAC-SHA1': 
  95. return hash_hmac('sha1', $data, $this->getSigningKey(), true); 
  96. default: 
  97. throw new UnsupportedHashAlgorithmException( 
  98. 'Unsupported hashing algorithm (' . $this->algorithm . ') used.' 
  99. );