DSB-PlugIn/AddOn/Calender_Google_User/oauth2callback.php

22 lines
628 B
PHP

<?php
//Lib from: https://github.com/googleapis/google-api-php-client/releases
require_once __DIR__ . '/google-api-php-client/vendor/autoload.php';
session_start();
$client = new Google_Client();
$client->setAuthConfig('credentials.json'); //Download from Google Cloud Admin Pannel
$client->setRedirectUri('<URL>/oauth2callback.php');
$client->addScope(Google_Service_Calendar::CALENDAR);
$client->setAccessType('offline');
if (!isset($_GET['code'])) {
die('Kein Code erhalten.');
}
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
$_SESSION['access_token'] = $token;
header('Location: index.php');
exit;