0fdce8be by Jeff Balicki

ee

1 parent 92597e10
...@@ -200,9 +200,8 @@ public function isGoogleFolderCreated($cust_id) ...@@ -200,9 +200,8 @@ public function isGoogleFolderCreated($cust_id)
200 200
201 public function GoogleToken() 201 public function GoogleToken()
202 { 202 {
203 203 session_start();
204 session_start(); 204 require_once realpath(dirname(__FILE__) . '/../autoload.php');
205
206 205
207 206
208 $client = new \Google_Client(); 207 $client = new \Google_Client();
...@@ -215,55 +214,85 @@ public function isGoogleFolderCreated($cust_id) ...@@ -215,55 +214,85 @@ public function isGoogleFolderCreated($cust_id)
215 214
216 $client->setApprovalPrompt('force'); 215 $client->setApprovalPrompt('force');
217 216
218 if (isset($_GET['code'])) {
219 $client->authenticate($_GET['code']);
220 $_SESSION['token'] = $client->getAccessToken();
221 $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
222 header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
223 return;
224 }
225
226 if (isset($_SESSION['token'])) {
227 $client->setAccessToken($_SESSION['token']);
228 }
229
230 if (isset($_REQUEST['logout'])) { 217 if (isset($_REQUEST['logout'])) {
231 unset($_SESSION['token']); 218 unset($_SESSION['access_token']);
232 $client->revokeToken(); 219 $client->revokeToken();
233 } 220 }
234 ?> 221
235 <!doctype html> 222 /************************************************
236 <html> 223 If we have a code back from the OAuth 2.0 flow,
237 <head> 224 we need to exchange that with the authenticate()
238 <meta charset="utf-8"> 225 function. We store the resultant access token
239 </head> 226 bundle in the session, and redirect to ourself.
240 <body> 227 ************************************************/
241 <header><h1>Get Token</h1></header> 228 if (isset($_GET['code'])) {
242 <?php 229 $client->authenticate($_GET['code']);
243 if ($client->getAccessToken()) { 230 $_SESSION['access_token'] = $client->getAccessToken();
244 $_SESSION['token'] = $client->getAccessToken(); 231 $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
245 $token = json_decode($_SESSION['token']); 232 header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
246 echo "Access Token = " . $token->access_token . '<br/>'; 233 }
247 echo "Refresh Token = " . $token->refresh_token . '<br/>'; 234
248 echo "Token type = " . $token->token_type . '<br/>'; 235 /************************************************
249 echo "Expires in = " . $token->expires_in . '<br/>'; 236 If we have an access token, we can make
250 //echo "ID Token = " . $token->id_token . '<br/>'; 237 requests, else we generate an authentication URL.
251 echo "Created = " . $token->created . '<br/>'; 238 ************************************************/
252 echo "<a class='logout' href='?logout'>Logout</a>"; 239 if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
253 } else { 240 $client->setAccessToken($_SESSION['access_token']);
254 $authUrl = $client->createAuthUrl(); 241 } else {
255 print "<a class='login' href='$authUrl'>Connect Me!</a><br/>"; 242 $authUrl = $client->createAuthUrl();
256 echo "<a class='logout' href='?logout'>Logout</a>"; 243 }
257 } 244
245 /************************************************
246 If we're signed in we can go ahead and retrieve
247 the ID token, which is part of the bundle of
248 data that is exchange in the authenticate step
249 - we only need to do a network call if we have
250 to retrieve the Google certificate to verify it,
251 and that can be cached.
252 ************************************************/
253 if ($client->getAccessToken()) {
254 $_SESSION['access_token'] = $client->getAccessToken();
255 $token_data = $client->verifyIdToken()->getAttributes();
256 }
257
258 echo pageHeader("User Query - Retrieving An Id Token");
259 if (
260 $client_id == '206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'
261 || $client_secret == 'ZzEE02Dqz7AKJLSklmL30LNd'
262 || $redirect_uri == 'http://localhost:8888/pdf-customizer/public/auth/google/tokenCallback') {
263 echo missingClientSecretsWarning();
264 }
265 ?>
266 <div class="box">
267 <div class="request">
268 <?php
269 if (isset($authUrl)) {
270 echo "<a class='login' href='" . $authUrl . "'>Connect Me!</a>";
271 } else {
272 echo "<a class='logout' href='?logout'>Logout</a>";
273 }
274 ?>
275 </div>
276
277 <div class="data">
278 <?php
279 if (isset($token_data)) {
280 var_dump($token_data);
281 }
282 ?>
283 </div>
284 </div>
285 <?php
286 echo pageFooter(__FILE__);
258 287
288
259 } 289 }
260 290
261 291
262 public function GoogleTokenCode($code) 292 public function GoogleTokenCode()
263 { 293 {
264
265 session_start(); 294 session_start();
266 295 require_once realpath(dirname(__FILE__) . '/../autoload.php');
267 296
268 297
269 $client = new \Google_Client(); 298 $client = new \Google_Client();
...@@ -276,39 +305,76 @@ public function isGoogleFolderCreated($cust_id) ...@@ -276,39 +305,76 @@ public function isGoogleFolderCreated($cust_id)
276 305
277 $client->setApprovalPrompt('force'); 306 $client->setApprovalPrompt('force');
278 307
279
280 $client->authenticate($_GET['code']);
281 $_SESSION['token'] = $client->getAccessToken();
282
283
284 if (isset($_SESSION['token'])) {
285 $client->setAccessToken($_SESSION['token']);
286 }
287
288 if (isset($_REQUEST['logout'])) { 308 if (isset($_REQUEST['logout'])) {
289 unset($_SESSION['token']); 309 unset($_SESSION['access_token']);
290 $client->revokeToken(); 310 $client->revokeToken();
291 } 311 }
292 ?> 312
293 <!doctype html> 313 /************************************************
294 <html> 314 If we have a code back from the OAuth 2.0 flow,
295 <head> 315 we need to exchange that with the authenticate()
296 <meta charset="utf-8"> 316 function. We store the resultant access token
297 </head> 317 bundle in the session, and redirect to ourself.
298 <body> 318 ************************************************/
299 <header><h1>Get Token</h1></header> 319 if (isset($_GET['code'])) {
300 <?php 320 $client->authenticate($_GET['code']);
301 321 $_SESSION['access_token'] = $client->getAccessToken();
302 $_SESSION['token'] = $client->getAccessToken(); 322 $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
303 $token = json_decode($_SESSION['token']); 323 header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
304 echo "Access Token = " . $token->access_token . '<br/>'; 324 }
305 echo "Refresh Token = " . $token->refresh_token . '<br/>'; 325
306 echo "Token type = " . $token->token_type . '<br/>'; 326 /************************************************
307 echo "Expires in = " . $token->expires_in . '<br/>'; 327 If we have an access token, we can make
308 //echo "ID Token = " . $token->id_token . '<br/>'; 328 requests, else we generate an authentication URL.
309 echo "Created = " . $token->created . '<br/>'; 329 ************************************************/
310 echo "<a class='logout' href='?logout'>Logout</a>"; 330 if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
311 331 $client->setAccessToken($_SESSION['access_token']);
332 } else {
333 $authUrl = $client->createAuthUrl();
334 }
335
336 /************************************************
337 If we're signed in we can go ahead and retrieve
338 the ID token, which is part of the bundle of
339 data that is exchange in the authenticate step
340 - we only need to do a network call if we have
341 to retrieve the Google certificate to verify it,
342 and that can be cached.
343 ************************************************/
344 if ($client->getAccessToken()) {
345 $_SESSION['access_token'] = $client->getAccessToken();
346 $token_data = $client->verifyIdToken()->getAttributes();
347 }
348
349 echo pageHeader("User Query - Retrieving An Id Token");
350 if (
351 $client_id == '206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'
352 || $client_secret == 'ZzEE02Dqz7AKJLSklmL30LNd'
353 || $redirect_uri == 'http://localhost:8888/pdf-customizer/public/auth/google/tokenCallback') {
354 echo missingClientSecretsWarning();
355 }
356 ?>
357 <div class="box">
358 <div class="request">
359 <?php
360 if (isset($authUrl)) {
361 echo "<a class='login' href='" . $authUrl . "'>Connect Me!</a>";
362 } else {
363 echo "<a class='logout' href='?logout'>Logout</a>";
364 }
365 ?>
366 </div>
367
368 <div class="data">
369 <?php
370 if (isset($token_data)) {
371 var_dump($token_data);
372 }
373 ?>
374 </div>
375 </div>
376 <?php
377 echo pageFooter(__FILE__);
312 378
313 } 379 }
314 380
......
...@@ -50,4 +50,4 @@ Route::post('fileentry/add',[ 'as' => 'addentry', 'uses' => 'FileEntryController ...@@ -50,4 +50,4 @@ Route::post('fileentry/add',[ 'as' => 'addentry', 'uses' => 'FileEntryController
50 Route::get('api/googlePdfUpload/{folder}/{filename}/{pdfid}/{id}', 'GoogledriveuploadpdfController@google_drive_upload'); 50 Route::get('api/googlePdfUpload/{folder}/{filename}/{pdfid}/{id}', 'GoogledriveuploadpdfController@google_drive_upload');
51 Route::get('auth/google/callback', 'GoogledriveuploadpdfController@google_drive_upload'); 51 Route::get('auth/google/callback', 'GoogledriveuploadpdfController@google_drive_upload');
52 Route::get('auth/google/token', 'GoogledriveuploadpdfController@GoogleToken'); 52 Route::get('auth/google/token', 'GoogledriveuploadpdfController@GoogleToken');
53 Route::get('auth/google/tokenCallback?{code}', 'GoogledriveuploadpdfController@GoogleTokenCode');
...\ No newline at end of file ...\ No newline at end of file
53 Route::get('auth/google/tokenCallback', 'GoogledriveuploadpdfController@GoogleTokenCode');
...\ No newline at end of file ...\ No newline at end of file
......