forked from jorgebg/yii-eoauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EOAuthProvider.php
53 lines (47 loc) · 1.71 KB
/
EOAuthProvider.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/*
* This product includes software developed at
* Google Inc. (http://www.google.es/about.html)
* under Apache 2.0 License (http://www.apache.org/licenses/LICENSE-2.0.html).
*
* See http://google-api-dfp-php.googlecode.com.
*
*/
/**
* Example implementation of an Ads OAuth provider.
*/
class EOAuthProvider extends EOAuthComponent/*OAuthProvider*/ {
public $consumer;
public $token;
public $request_token_endpoint=
'https://www.google.com/accounts/OAuthGetRequestToken';
public $authorize_token_endpoint =
'https://www.google.com/accounts/OAuthAuthorizeToken';
public $access_token_endpoint =
'https://www.google.com/accounts/OAuthGetAccessToken';
/**
* Constructor for EOAuthProvider.
* @param OAuthConsumer $consumer the OAuth consumer
* @param OAuthToken $token the OAuth access token
*/
public function __construct($consumer=null, $token=null) {
$this->consumer = $consumer;
$this->token = $token;
}
/**
* Returns the value of the OAuth Authorization HTTP header for a given
* endpoint URL.
* @param string $url the endpoint URL to authorize against
* @return string the OAuth Authorization HTTP header value
*/
public function GetOAuthHeader($url) {
$signatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
$request = OAuthRequest::from_consumer_and_token($this->consumer,
$this->token, 'POST', $url, array());
$request->sign_request($signatureMethod, $this->consumer, $this->token);
$header = $request->to_header();
// Remove "Authorization:" prefix.
$pieces = explode(':', $header, 2);
return trim($pieces[1]);
}
}