mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
Feature/merge 3 0 develop (#298)
* merging 3.0 into develop * N°5102 - Allow to send emails (eg. notifications) using GSuite SMTP and OAuth * migration to iTop 3.1 Co-authored-by: Eric Espie <eric.espie@combodo.com>
This commit is contained in:
35
lib/league/oauth2-google/examples/index.php
Normal file
35
lib/league/oauth2-google/examples/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
$provider = require __DIR__ . '/provider.php';
|
||||
|
||||
if (!empty($_GET['error'])) {
|
||||
|
||||
// Got an error, probably user denied access
|
||||
exit('Got error: ' . htmlspecialchars($_GET['error'], ENT_QUOTES, 'UTF-8'));
|
||||
|
||||
} elseif (empty($_GET['code'])) {
|
||||
|
||||
// If we don't have an authorization code then get one
|
||||
$authUrl = $provider->getAuthorizationUrl();
|
||||
$_SESSION['oauth2state'] = $provider->getState();
|
||||
header('Location: ' . $authUrl);
|
||||
exit;
|
||||
|
||||
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
|
||||
|
||||
// State is invalid, possible CSRF attack in progress
|
||||
unset($_SESSION['oauth2state']);
|
||||
exit('Invalid state');
|
||||
|
||||
} else {
|
||||
|
||||
// Try to get an access token (using the authorization code grant)
|
||||
$token = $provider->getAccessToken('authorization_code', [
|
||||
'code' => $_GET['code']
|
||||
]);
|
||||
|
||||
$_SESSION['token'] = serialize($token);
|
||||
|
||||
// Optional: Now you have a token you can look up a users profile data
|
||||
header('Location: /user.php');
|
||||
}
|
||||
Reference in New Issue
Block a user