1 | <?php |
||
9 | class DropboxAuthHelper |
||
10 | { |
||
11 | /** |
||
12 | * The length of CSRF string |
||
13 | * |
||
14 | * @const int |
||
15 | */ |
||
16 | const CSRF_LENGTH = 32; |
||
17 | |||
18 | /** |
||
19 | * OAuth2 Client |
||
20 | * |
||
21 | * @var \Dropbox\Authentication\OAuth2Client |
||
22 | */ |
||
23 | protected $oAuth2Client; |
||
24 | |||
25 | /** |
||
26 | * Random String Generator |
||
27 | * |
||
28 | * @var \Dropbox\Security\RandomStringGeneratorInterface |
||
29 | */ |
||
30 | protected $randomStringGenerator; |
||
31 | |||
32 | /** |
||
33 | * Persistent Data Store |
||
34 | * |
||
35 | * @var \Dropbox\Store\PersistentDataStoreInterface |
||
36 | */ |
||
37 | protected $persistentDataStore; |
||
38 | |||
39 | /** |
||
40 | * Additional User Provided State |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $urlState = null; |
||
45 | |||
46 | /** |
||
47 | * Create a new DropboxAuthHelper instance |
||
48 | * |
||
49 | * @param \Dropbox\Authentication\OAuth2Client $oAuth2Client |
||
50 | * @param \Dropbox\Security\RandomStringGeneratorInterface $randomStringGenerator |
||
51 | * @param \Dropbox\Store\PersistentDataStoreInterface $persistentDataStore |
||
52 | */ |
||
53 | public function __construct( |
||
62 | |||
63 | /** |
||
64 | * Get OAuth2Client |
||
65 | * |
||
66 | * @return \Dropbox\Authentication\OAuth2Client |
||
67 | */ |
||
68 | public function getOAuth2Client() |
||
72 | |||
73 | /** |
||
74 | * Get the Random String Generator |
||
75 | * |
||
76 | * @return \Dropbox\Security\RandomStringGeneratorInterface |
||
77 | */ |
||
78 | public function getRandomStringGenerator() |
||
82 | |||
83 | /** |
||
84 | * Get the Persistent Data Store |
||
85 | * |
||
86 | * @return \Dropbox\Store\PersistentDataStoreInterface |
||
87 | */ |
||
88 | public function getPersistentDataStore() |
||
92 | |||
93 | /** |
||
94 | * Get CSRF Token |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | protected function getCsrfToken() |
||
104 | |||
105 | /** |
||
106 | * Get Authorization URL |
||
107 | * |
||
108 | * @param string $redirectUri Callback URL to redirect to after authorization |
||
109 | * @param array $params Additional Params |
||
110 | * @param string $urlState Additional User Provided State Data |
||
111 | * |
||
112 | * @link https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | public function getAuthUrl($redirectUri = null, array $params = [], $urlState = null) |
||
145 | |||
146 | /** |
||
147 | * Decode State to get the CSRF Token and the URL State |
||
148 | * |
||
149 | * @param string $state State |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | protected function decodeState($state) |
||
167 | |||
168 | /** |
||
169 | * Validate CSRF Token |
||
170 | * @param string $csrfToken CSRF Token |
||
171 | * |
||
172 | * @throws DropboxClientException |
||
173 | * |
||
174 | * @return void |
||
175 | */ |
||
176 | protected function validateCSRFToken($csrfToken) |
||
193 | |||
194 | /** |
||
195 | * Get Access Token |
||
196 | * |
||
197 | * @param string $code Authorization Code |
||
198 | * @param string $state CSRF & URL State |
||
199 | * @param string $redirectUri Redirect URI used while getAuthUrl |
||
200 | * |
||
201 | * @return \Dropbox\Models\AccessToken |
||
202 | */ |
||
203 | public function getAccessToken($code, $state = null, $redirectUri = null) |
||
228 | |||
229 | /** |
||
230 | * Revoke Access Token |
||
231 | * |
||
232 | * @return void |
||
233 | */ |
||
234 | public function revokeAccessToken() |
||
238 | |||
239 | /** |
||
240 | * Get URL State |
||
241 | * |
||
242 | * @return string |
||
243 | */ |
||
244 | public function getUrlState() |
||
248 | } |
||
249 |