oauth_callback.php 799 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. require __DIR__ . '/vendor/autoload.php';
  3. use Google\Client;
  4. $client = new Client();
  5. $client->setAuthConfig('/var/www/secure/oauth-client.json');
  6. $client->setRedirectUri('https://llm.modulos.com.au/oauth_callback.php');
  7. $client->setScopes([
  8. Google\Service\Drive::DRIVE,
  9. Google\Service\Docs::DOCUMENTS
  10. ]);
  11. if (!isset($_GET['code'])) {
  12. http_response_code(400);
  13. echo 'Missing ?code';
  14. exit;
  15. }
  16. $token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
  17. if (isset($token['error'])) {
  18. http_response_code(500);
  19. echo 'OAuth error: ' . htmlspecialchars(json_encode($token));
  20. exit;
  21. }
  22. file_put_contents(__DIR__ . '/cache/gdocs_token.json', json_encode($token, JSON_PRETTY_PRINT));
  23. echo '<h3>Connected ✅</h3><p>You can close this tab and try “Create Google Doc” again.</p>';