|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Evernote\Auth; |
|
4
|
|
|
|
|
5
|
|
|
class EvernoteOauth extends \Evernote\Auth\OauthHandler |
|
6
|
|
|
{ |
|
7
|
|
|
protected $params = array(); |
|
8
|
|
|
|
|
9
|
|
|
public function authorize($consumer_key, $consumer_secret, $callback) |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
$this->params['oauth_callback'] = $callback; |
|
12
|
|
|
$this->params['oauth_consumer_key'] = $consumer_key; |
|
13
|
|
|
|
|
14
|
|
|
$this->consumer_secret = $consumer_secret; |
|
15
|
|
|
|
|
16
|
|
|
// first call |
|
17
|
|
|
if (!array_key_exists('oauth_verifier', $_GET) && !array_key_exists('oauth_token', $_GET)) { |
|
18
|
|
|
|
|
19
|
|
|
unset($this->params['oauth_token']); |
|
20
|
|
|
unset($this->params['oauth_verifier']); |
|
21
|
|
|
|
|
22
|
|
|
$temporaryCredentials = $this->getTemporaryCredentials(); |
|
23
|
|
|
|
|
24
|
|
|
Session::set('oauth_token_secret', $temporaryCredentials['oauth_token_secret']); |
|
25
|
|
|
|
|
26
|
|
|
$authorizationUrl = 'Location: ' |
|
27
|
|
|
. $this->getBaseUrl('OAuth.action?oauth_token=') |
|
28
|
|
|
. $temporaryCredentials['oauth_token']; |
|
29
|
|
|
|
|
30
|
|
|
if ($this->supportLinkedSandbox) { |
|
31
|
|
|
$authorizationUrl .= '&supportLinkedSandbox=true'; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
header($authorizationUrl); |
|
35
|
|
|
|
|
36
|
|
|
// the user declined the authorization |
|
37
|
|
|
} elseif (!array_key_exists('oauth_verifier', $_GET) && array_key_exists('oauth_token', $_GET)) { |
|
38
|
|
|
throw new AuthorizationDeniedException('Authorization declined.'); |
|
39
|
|
|
//the user authorized the app |
|
40
|
|
|
} else { |
|
41
|
|
|
$this->token_secret = Session::get('oauth_token_secret'); |
|
42
|
|
|
|
|
43
|
|
|
$this->params['oauth_token'] = $_GET['oauth_token']; |
|
44
|
|
|
$this->params['oauth_verifier'] = $_GET['oauth_verifier']; |
|
45
|
|
|
unset($this->params['oauth_callback']); |
|
46
|
|
|
|
|
47
|
|
|
return $this->getTemporaryCredentials(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
} |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: