-
Notifications
You must be signed in to change notification settings - Fork 454
/
google.php
43 lines (36 loc) · 1.41 KB
/
google.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
use OAuth\Common\Consumer\Credentials;
use OAuth\Common\Http\Client\CurlClient;
use OAuth\Common\Http\Exception\TokenResponseException;
use OAuth\Common\Storage\Session;
use OAuth\Helper\Example;
use OAuth\OAuth2\Service\Google;
require_once __DIR__ . '/../bootstrap.php';
$helper = new Example();
$storage = new Session();
$client = new CurlClient();
$helper->setTitle('Google');
if (empty($_GET)) {
echo $helper->getContent();
} elseif (!empty($_GET['key']) && !empty($_GET['secret']) && $_GET['oauth'] !== 'redirect') {
echo $helper->getHeader();
try {
$credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl());
$google = new Google($credentials, $client, $storage, ['email']);
echo '<a href="' . $google->getAuthorizationUri() . '">get access token</a>';
} catch (\Exception $exception) {
$helper->getErrorMessage($exception);
}
echo $helper->getFooter();
} elseif (!empty($_GET['code'])) {
$credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl());
$google = new Google($credentials, $client, $storage);
echo $helper->getHeader();
try {
$token = $google->requestAccessToken($_GET['code']);
echo 'access token: ' . $token->getAccessToken();
} catch (TokenResponseException $exception) {
$helper->getErrorMessage($exception);
}
echo $helper->getFooter();
}