verifymyagecouk / verifymyage-oauth
VerifyMyAge OAuth 验证
2.1.0
2023-01-31 12:14 UTC
Requires
- league/oauth2-client: ^2.6
This package is auto-updated.
Last update: 2024-09-27 13:34:54 UTC
README
PHP SDK,用于使用 VerifyMyAge OAuth 服务。
安装
composer require verifymyagecouk/verifymyage-oauth
开始使用
<?php require(__DIR__ . "/vendor/autoload.php"); $vma = new VerifyMyAge\OAuth(getenv('VMA_CLIENT_ID'), getenv('VMA_CLIENT_SECRET'), getenv('VMA_REDIRECT_URL')); //$vma->useSandbox(); // Redirect or show age-gate if we don't have a code yet if (!isset($_GET['code'])) { $redirectURL = $vma->redirectURL(VerifyMyAge\Countries::GERMANY); $_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()); } }
国家选项
VerifyMyAge\Countries::FRANCE
VerifyMyAge\Countries::GERMANY
VerifyMyAge\Countries::UNITED_KINGDOM