32 lines
1.1 KiB
PHP
32 lines
1.1 KiB
PHP
<?php
|
|
|
|
//require(__DIR__ . "/vendor/autoload.php");
|
|
require($serverpath."vendor/autoload.php");
|
|
|
|
$vma = new VerifyMyAge\OAuth(getenv('key-d-c517285c-e4c9-467a-8e70-bdf4be3a2605'), getenv('secret-d-4aa58055-4bcd-4902-968d-ddb0bb21c7c5'), getenv('http://localhost'));
|
|
$vma->useSandbox();
|
|
|
|
// Redirect or show age-gate if we don't have a code yet
|
|
if (!isset($_GET['code'])) {
|
|
$redirectURL = $vma->redirectURL();
|
|
$_SESSION['oauth2state'] = $vma->state();
|
|
header('Location: ' . $redirectURL);
|
|
exit;
|
|
|
|
// Avoid CSRF attack
|
|
} elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && $_GET['state'] !== $_SESSION['oauth2state'])) {
|
|
if (isset($_SESSION['oauth2state'])) {
|
|
unset($_SESSION['oauth2state']);
|
|
}
|
|
exit('Invalid state');
|
|
} else {
|
|
try {
|
|
// Try to get an access token using the authorization code grant.
|
|
$accessToken = $vma->exchangeCodeByToken($_GET['code']);
|
|
$user = $vma->user($accessToken);
|
|
var_export($user);
|
|
} catch (\Exception $e) {
|
|
// Failed to get the access token or user details.
|
|
exit($e->getMessage());
|
|
}
|
|
}?>
|