Last active 1731260292

Revision 3eb392de6c6593de56dbc3771133ed4f60d779f2

composer.json Raw
1{
2 "require": {
3 "jumbojett/openid-connect-php": "^1.0"
4 }
5}
6
index_partial.php Raw
1<?php // -*-c++-*-
2
3# debug mode, don't do that on a live service
4ini_set('display_errors', 1);
5ini_set('display_startup_errors', 1);
6error_reporting(E_ALL);
7
8require __DIR__ . '/vendor/autoload.php';
9
10use Jumbojett\OpenIDConnectClient;
11
12session_start();
13
14if(isset($_SESSION['oidc'])) {
15 $oidc=$_SESSION['oidc'];
16
17 try {
18 $id=$oidc->requestUserInfo('email');
19 } catch(Exception $e) {
20 try {
21 $oidc->authenticate();
22 $id=$oidc->requestUserInfo('email');
23 } catch(Exception $e) {
24 echo "reauthentication failed.";
25 exit(0);
26 }
27 }
28
29 if(!isset($id)) {
30 echo "could not get login name from oidc session\n";
31 exit(0);
32 }
33
34# if we are on the first request from the oidc provider, send a redirect
35 if(isset($_GET['code'])) {
36 header("Location: .");
37 exit(0);
38 }
39} else {
40
41 try {
42 $oidc = new OpenIDConnectClient('https://id.tilde.green/realms/tgci',
43 'CLIENTID',
44 'CLIENTSECRET');
45 $oidc->authenticate();
46 #$name = $oidc->requestUserInfo('user_id');
47 } catch (Exception $e) {
48 echo '<pre>Caught exception: ', $e->getMessage(), "\n";
49 echo $e->getTraceAsString(), "</pre>\n";
50 exit(0);
51 }
52 $_SESSION['oidc']=$oidc;
53
54 if(isset($_GET['code'])) {
55 header("Location: .");
56 exit(0);
57 }
58}
59
60