Created
October 18, 2023 09:02
-
-
Save Zeko369/63d2f63a51884a1ef36f8c0e5b23bebe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require '../vendor/autoload.php'; | |
use Jumbojett\OpenIDConnectClient; | |
$local_url = "http://localhost:5001"; | |
session_start(); | |
if (isset($_GET['clear_session'])) { | |
$_SESSION = array(); | |
} | |
try { | |
$oidc = new OpenIDConnectClient( | |
'http://localhost:3000', | |
'ghDs--eUbxzRdCu2VeslQvqnHYjURmc6VdKMoLHnC0E', // client ID | |
'jpGwyoBQWpUuYOCCb3PhNpJ4N4r1lE7Hh__BoLJifJ4', // client Secret | |
); | |
// $oidc->setVerifyHost(false); | |
// $oidc->setVerifyPeer(false); | |
// $oidc->setHttpUpgradeInsecureRequests(false); | |
$oidc->setAllowImplicitFlow(true); | |
$oidc->setResponseTypes(array('code')); | |
$oidc->addScope(array('openid', 'email', 'profile')); | |
$oidc->setRedirectURL($local_url); | |
if (!isset($_SESSION['access_token'])) { | |
// $oidc->addAuthParam(array('response_mode' => 'form_post')); | |
$oidc->authenticate(); // Redirect to the OpenID Connect provider | |
$_SESSION['access_token'] = $oidc->getAccessToken(); | |
header('Location: ' . $local_url); | |
} else { | |
$oidc->setAccessToken($_SESSION['access_token']); | |
} | |
$user = json_encode($oidc->requestUserInfo()); | |
print_r($user); | |
print_r($_SESSION); | |
echo $oidc->requestUserInfo('email'); | |
} catch (\Throwable $th) { | |
echo $th->getMessage(); | |
error_log($th->getMessage()); | |
} | |
echo "<a href='$local_url?clear_session=true'>Clear session</a>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment