e
Showing
2 changed files
with
59 additions
and
1 deletions
| ... | @@ -91,4 +91,61 @@ class GoogledriveuploadpdfController extends Controller | ... | @@ -91,4 +91,61 @@ class GoogledriveuploadpdfController extends Controller |
| 91 | 91 | ||
| 92 | 92 | ||
| 93 | } | 93 | } |
| 94 | |||
| 95 | public function GoogleToken() | ||
| 96 | { | ||
| 97 | |||
| 98 | session_start(); | ||
| 99 | |||
| 100 | |||
| 101 | |||
| 102 | $client = new \Google_Client(); | ||
| 103 | $client->setScopes(array('https://www.googleapis.com/auth/drive.file')); | ||
| 104 | $client->setClientId('206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'); | ||
| 105 | $client->setClientSecret('qmUMAi09SU4wU4R3uOkvsiwK'); | ||
| 106 | $client->setRedirectUri('http://pdf-customizer.synapsus.co/auth/google/callback'); | ||
| 107 | $client->setAccessType('offline'); | ||
| 108 | |||
| 109 | if (isset($_GET['code'])) { | ||
| 110 | $client->authenticate($_GET['code']); | ||
| 111 | $_SESSION['token'] = $client->getAccessToken(); | ||
| 112 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; | ||
| 113 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); | ||
| 114 | return; | ||
| 115 | } | ||
| 116 | |||
| 117 | if (isset($_SESSION['token'])) { | ||
| 118 | $client->setAccessToken($_SESSION['token']); | ||
| 119 | } | ||
| 120 | |||
| 121 | if (isset($_REQUEST['logout'])) { | ||
| 122 | unset($_SESSION['token']); | ||
| 123 | $client->revokeToken(); | ||
| 124 | } | ||
| 125 | ?> | ||
| 126 | <!doctype html> | ||
| 127 | <html> | ||
| 128 | <head> | ||
| 129 | <meta charset="utf-8"> | ||
| 130 | </head> | ||
| 131 | <body> | ||
| 132 | <header><h1>Get Token</h1></header> | ||
| 133 | <?php | ||
| 134 | if ($client->getAccessToken()) { | ||
| 135 | $_SESSION['token'] = $client->getAccessToken(); | ||
| 136 | $token = json_decode($_SESSION['token']); | ||
| 137 | echo "Access Token = " . $token->access_token . '<br/>'; | ||
| 138 | echo "Refresh Token = " . $token->refresh_token . '<br/>'; | ||
| 139 | echo "Token type = " . $token->token_type . '<br/>'; | ||
| 140 | echo "Expires in = " . $token->expires_in . '<br/>'; | ||
| 141 | echo "ID Token = " . $token->id_token . '<br/>'; | ||
| 142 | echo "Created = " . $token->created . '<br/>'; | ||
| 143 | echo "<a class='logout' href='?logout'>Logout</a>"; | ||
| 144 | } else { | ||
| 145 | $authUrl = $client->createAuthUrl(); | ||
| 146 | print "<a class='login' href='$authUrl'>Connect Me!</a>"; | ||
| 147 | } | ||
| 148 | |||
| 149 | } | ||
| 150 | |||
| 94 | } | 151 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -53,4 +53,5 @@ Route::post('fileentry/add',[ | ... | @@ -53,4 +53,5 @@ Route::post('fileentry/add',[ |
| 53 | 'as' => 'addentry', 'uses' => 'FileEntryController@add']); | 53 | 'as' => 'addentry', 'uses' => 'FileEntryController@add']); |
| 54 | 54 | ||
| 55 | Route::get('api/googlePdfUpload/{folder}/{filename}', 'GoogledriveuploadpdfController@google_drive_upload'); | 55 | Route::get('api/googlePdfUpload/{folder}/{filename}', 'GoogledriveuploadpdfController@google_drive_upload'); |
| 56 | Route::get('auth/google/callback', 'GoogledriveuploadpdfController@google_drive_upload'); | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 56 | Route::get('auth/google/callback', 'GoogledriveuploadpdfController@google_drive_upload'); | ||
| 57 | Route::get('auth/google/token', 'GoogledriveuploadpdfController@GoogleToken'); | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment