-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconsumer.php
38 lines (26 loc) · 1.05 KB
/
consumer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
require_once dirname(__FILE__) . '/../library/OAuth/OAuth.php';
// this is sent with each request, and doesn't matter if it is public
$consumer_key = 'thisisakey';
// this should never be sent directly over the wire
$private_key = 'thisisasecret';
// API endpoint
$url = 'https://example.com/v1/oauth';
// the custom paramters you want to send to the endpoint
$params = array( 'foo' => 'bar',
'bar' => 'foo',
);
$consumer = new OAuthConsumer($consumer_key, $private_key);
$request = OAuthRequest::from_consumer_and_token($consumer, NULL, 'GET', $url, $params);
$sig = new OAuthSignatureMethod_HMAC_SHA1();
$request->sign_request($sig, $consumer, null);
$opts = array(
'http' => array(
'header' => $request->to_header()
)
);
$context = stream_context_create($opts);
$url = $url . '?' . http_build_query($params);
echo "Making request: " . $url . PHP_EOL;
echo "Authorization HTTP Header: " . $request->to_header() . PHP_EOL;
echo "Response: " . file_get_contents($url, false, $context) . PHP_EOL;