', '', '' // pass '' for public clients ); $oidc->setRedirectURL(''); $oidc->addScope(['openid', 'profile', 'email']); $oidc->setCodeChallengeMethod('S256'); // PKCE // The library fetches /.well-known/openid-configuration on first use // and caches endpoints in the session. $oidc->authenticate(); // redirects to /oauth2/v1/authorize on first hit, // handles the callback exchange on second hit. $_SESSION['user'] = [ 'sub' => $oidc->getVerifiedClaims('sub'), 'name' => $oidc->requestUserInfo('preferred_username'), 'role' => $oidc->requestUserInfo('role') ?: 'user', ]; header('Content-Type: application/json'); echo json_encode($_SESSION['user']);