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'])) { 217 if (isset($_REQUEST['logout'])) {
218 unset($_SESSION['access_token']);
219 $client->revokeToken();
220 }
221
222 /************************************************
223 If we have a code back from the OAuth 2.0 flow,
224 we need to exchange that with the authenticate()
225 function. We store the resultant access token
226 bundle in the session, and redirect to ourself.
227 ************************************************/
228 if (isset($_GET['code'])) {
219 $client->authenticate($_GET['code']); 229 $client->authenticate($_GET['code']);
220 $_SESSION['token'] = $client->getAccessToken(); 230 $_SESSION['access_token'] = $client->getAccessToken();
221 $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 231 $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
222 header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 232 header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
223 return; 233 }
224 }
225
226 if (isset($_SESSION['token'])) {
227 $client->setAccessToken($_SESSION['token']);
228 }
229 234
230 if (isset($_REQUEST['logout'])) { 235 /************************************************
231 unset($_SESSION['token']); 236 If we have an access token, we can make
232 $client->revokeToken(); 237 requests, else we generate an authentication URL.
233 } 238 ************************************************/
234 ?> 239 if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
235 <!doctype html> 240 $client->setAccessToken($_SESSION['access_token']);
236 <html> 241 } else {
237 <head>
238 <meta charset="utf-8">
239 </head>
240 <body>
241 <header><h1>Get Token</h1></header>
242 <?php
243 if ($client->getAccessToken()) {
244 $_SESSION['token'] = $client->getAccessToken();
245 $token = json_decode($_SESSION['token']);
246 echo "Access Token = " . $token->access_token . '<br/>';
247 echo "Refresh Token = " . $token->refresh_token . '<br/>';
248 echo "Token type = " . $token->token_type . '<br/>';
249 echo "Expires in = " . $token->expires_in . '<br/>';
250 //echo "ID Token = " . $token->id_token . '<br/>';
251 echo "Created = " . $token->created . '<br/>';
252 echo "<a class='logout' href='?logout'>Logout</a>";
253 } else {
254 $authUrl = $client->createAuthUrl(); 242 $authUrl = $client->createAuthUrl();
255 print "<a class='login' href='$authUrl'>Connect Me!</a><br/>"; 243 }
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 {
256 echo "<a class='logout' href='?logout'>Logout</a>"; 272 echo "<a class='logout' href='?logout'>Logout</a>";
257 } 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__);
287
258 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
308 if (isset($_REQUEST['logout'])) {
309 unset($_SESSION['access_token']);
310 $client->revokeToken();
311 }
279 312
313 /************************************************
314 If we have a code back from the OAuth 2.0 flow,
315 we need to exchange that with the authenticate()
316 function. We store the resultant access token
317 bundle in the session, and redirect to ourself.
318 ************************************************/
319 if (isset($_GET['code'])) {
280 $client->authenticate($_GET['code']); 320 $client->authenticate($_GET['code']);
281 $_SESSION['token'] = $client->getAccessToken(); 321 $_SESSION['access_token'] = $client->getAccessToken();
322 $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
323 header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
324 }
282 325
326 /************************************************
327 If we have an access token, we can make
328 requests, else we generate an authentication URL.
329 ************************************************/
330 if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
331 $client->setAccessToken($_SESSION['access_token']);
332 } else {
333 $authUrl = $client->createAuthUrl();
334 }
283 335
284 if (isset($_SESSION['token'])) { 336 /************************************************
285 $client->setAccessToken($_SESSION['token']); 337 If we're signed in we can go ahead and retrieve
286 } 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 }
287 348
288 if (isset($_REQUEST['logout'])) { 349 echo pageHeader("User Query - Retrieving An Id Token");
289 unset($_SESSION['token']); 350 if (
290 $client->revokeToken(); 351 $client_id == '206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'
291 } 352 || $client_secret == 'ZzEE02Dqz7AKJLSklmL30LNd'
292 ?> 353 || $redirect_uri == 'http://localhost:8888/pdf-customizer/public/auth/google/tokenCallback') {
293 <!doctype html> 354 echo missingClientSecretsWarning();
294 <html> 355 }
295 <head> 356 ?>
296 <meta charset="utf-8"> 357 <div class="box">
297 </head> 358 <div class="request">
298 <body> 359 <?php
299 <header><h1>Get Token</h1></header> 360 if (isset($authUrl)) {
300 <?php 361 echo "<a class='login' href='" . $authUrl . "'>Connect Me!</a>";
301 362 } else {
302 $_SESSION['token'] = $client->getAccessToken();
303 $token = json_decode($_SESSION['token']);
304 echo "Access Token = " . $token->access_token . '<br/>';
305 echo "Refresh Token = " . $token->refresh_token . '<br/>';
306 echo "Token type = " . $token->token_type . '<br/>';
307 echo "Expires in = " . $token->expires_in . '<br/>';
308 //echo "ID Token = " . $token->id_token . '<br/>';
309 echo "Created = " . $token->created . '<br/>';
310 echo "<a class='logout' href='?logout'>Logout</a>"; 363 echo "<a class='logout' href='?logout'>Logout</a>";
364 }
365 ?>
366 </div>
311 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
......