Files
Fitness/web/callback.php
T

33 lines
978 B
PHP

<?php
require __DIR__ . '/../vendor/autoload.php';
use Jumbojett\OpenIDConnectClient;
session_start();
$config = require __DIR__ . '/config.php';
$oidc = new OpenIDConnectClient(
$config['provider_url'],
$config['client_id'],
$config['client_secret']
);
$oidc->setRedirectURL($config['redirect_uri']);
$oidc->addScope($config['scopes']);
$oidc->setResponseTypes([$config['response_type']]);
// This will read the `code` query parameter, fetch the tokens
// and validate everything.
$oidc->authenticate();
// Fetch the OpenID Connect userinfo claims
$claims = $oidc->requestUserInfo(); // → stdClass with the claims
// Store what we need in the PHP session
$_SESSION['authenticated'] = true;
$_SESSION['name'] = $claims->name ?? $claims->given_name ?? $claims->family_name ?? '';
$_SESSION['email'] = $claims->email ?? '';
$_SESSION['groups'] = $claims->groups ?? [];
// Redirect back to the home page
header('Location: ../');
exit;