1 | <?php |
||
9 | class OAuth2Client |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * The Base URL |
||
14 | * |
||
15 | * @const string |
||
16 | */ |
||
17 | const BASE_URL = "https://dropbox.com"; |
||
18 | |||
19 | /** |
||
20 | * Auth Token URL |
||
21 | * |
||
22 | * @const string |
||
23 | */ |
||
24 | const AUTH_TOKEN_URL = "https://api.dropboxapi.com/oauth2/token"; |
||
25 | |||
26 | /** |
||
27 | * The Dropbox App |
||
28 | * |
||
29 | * @var \Dropbox\DropboxApp |
||
30 | */ |
||
31 | protected $app; |
||
32 | |||
33 | /** |
||
34 | * The Dropbox Client |
||
35 | * |
||
36 | * @var \Dropbox\DropboxClient |
||
37 | */ |
||
38 | protected $client; |
||
39 | |||
40 | /** |
||
41 | * Random String Generator |
||
42 | * |
||
43 | * @var \Dropbox\Security\RandomStringGeneratorInterface |
||
44 | */ |
||
45 | protected $randStrGenerator; |
||
46 | |||
47 | /** |
||
48 | * Create a new DropboxApp instance |
||
49 | * |
||
50 | * @param \Dropbox\DropboxApp $app |
||
51 | * @param \Dropbox\DropboxClient $client |
||
52 | * @param \Dropbox\Security\RandomStringGeneratorInterface $randStrGenerator |
||
53 | */ |
||
54 | public function __construct(DropboxApp $app, DropboxClient $client, RandomStringGeneratorInterface $randStrGenerator = null) |
||
60 | |||
61 | /** |
||
62 | * Build URL |
||
63 | * |
||
64 | * @param string $endpoint |
||
65 | * @param array $params Query Params |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | protected function buildUrl($endpoint = '', array $params = []) |
||
74 | |||
75 | /** |
||
76 | * Get the Dropbox App |
||
77 | * |
||
78 | * @return \Dropbox\DropboxApp |
||
79 | */ |
||
80 | public function getApp() |
||
84 | |||
85 | /** |
||
86 | * Get the Dropbox Client |
||
87 | * |
||
88 | * @return \Dropbox\DropboxClient |
||
89 | */ |
||
90 | public function getClient() |
||
94 | |||
95 | /** |
||
96 | * Get the OAuth2 Authorization URL |
||
97 | * |
||
98 | * @param string $redirectUri Callback URL to redirect user after authorization. |
||
99 | * If null is passed, redirect_uri will be omitted |
||
100 | * from the url and the code will be presented directly |
||
101 | * to the user. |
||
102 | * @param string $state CSRF Token |
||
103 | * @param array $params Additional Params |
||
104 | * |
||
105 | * @link https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | public function getAuthorizationUrl($redirectUri = null, $state = null, array $params = []) |
||
124 | |||
125 | /** |
||
126 | * Get Access Token |
||
127 | * |
||
128 | * @param string $code Authorization Code |
||
129 | * @param string $redirectUri Redirect URI used while getAuthorizationUrl |
||
130 | * @param string $grant_type Grant Type ['authorization_code'] |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | public function getAccessToken($code, $redirectUri = null, $grant_type = 'authorization_code') |
||
163 | |||
164 | /** |
||
165 | * Disables the access token |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | public function revokeAccessToken() |
||
185 | } |
||
186 |