psr12 fixes for new PHP_CodeSniffer (#4795)
[openemr.git] / portal / patient / fwk / libs / verysimple / Authentication / OAuthUtil.php
blob3f8b346d99d3e0759aec458b74adcad399d241d3
1 <?php
3 /** @package verysimple::Authentication */
5 require_once "oauth/OAuthStore.php";
6 require_once "oauth/OAuthRequester.php";
7 require_once "verysimple/String/VerySimpleStringUtil.php";
9 /**
10 * A set of utility functions for working with OAuth
12 * @package verysimple::String
13 * @author Jason Hinkle
14 * @copyright 1997-2012 VerySimple, Inc.
15 * @license http://www.gnu.org/licenses/lgpl.html LGPL
16 * @version 1.0
18 class OAuthUtil
20 /**
21 * Given a URL return an OAuth signed URL.
22 * This will handle creating a timestamp and nonce
24 * @param string $url
25 * the unsigned url
26 * @param string $method
27 * request method GET, POST, PUT, DELETE
28 * @param string $key
29 * oauth key
30 * @param string $secret
31 * oauth secret
32 * @param array $params
33 * querystring or post parameters
34 * @param string $body
35 * the body contents of the request
36 * @param string $signature_method
37 * method used for signature (default = 'HMAC_SHA1')
39 public static function SignUrl($url, $method, $key, $secret, $params = null, $body = null, $signature_method = 'HMAC_SHA1')
41 $options = array (
42 'consumer_key' => $key,
43 'consumer_secret' => $secret
45 $params = $params ? $params : array ();
47 OAuthStore::instance("2Leg", $options);
49 // Obtain a request object for the request we want to make
50 $request = new OAuthRequester($url, $method, $params, $body);
52 $sig = $request->sign($key, null, '');
54 $data = $request->signatureBaseString();
56 $url = substr(urldecode($data . '&oauth_signature=' . $request->calculateDataSignature($data, $secret, '', $signature_method)), strlen($method) + 1);
58 $url = VerySimpleStringUtil::ReplaceFirst('&', '?', $url);
60 return $url;