22 lines
681 B
PHP
22 lines
681 B
PHP
<?php
|
|
// auth.php
|
|
|
|
require_once 'vendor/autoload.php';
|
|
exit;
|
|
session_start();
|
|
|
|
$client = new Google_Client();
|
|
$client->setClientId('YOUR_CLIENT_ID');
|
|
$client->setClientSecret('YOUR_CLIENT_SECRET');
|
|
$client->setRedirectUri('YOUR_REDIRECT_URI'); // e.g., http://localhost/yourproject/auth.php
|
|
$client->addScope(Google_Service_Tasks::TASKS);
|
|
|
|
if (!isset($_GET['code'])) {
|
|
$auth_url = $client->createAuthUrl();
|
|
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
|
|
} else {
|
|
$client->authenticate($_GET['code']);
|
|
$_SESSION['access_token'] = $client->getAccessToken();
|
|
header('Location: ' . filter_var($client->getRedirectUri(), FILTER_SANITIZE_URL));
|
|
}
|