1 | { |
2 | "require": { |
3 | "jumbojett/openid-connect-php": "^1.0" |
4 | } |
5 | } |
6 |
index_partial.php
· 1.2 KiB · PHP
Raw
<?php // -*-c++-*-
# debug mode, don't do that on a live service
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
use Jumbojett\OpenIDConnectClient;
session_start();
if(isset($_SESSION['oidc'])) {
$oidc=$_SESSION['oidc'];
try {
$id=$oidc->requestUserInfo('email');
} catch(Exception $e) {
try {
$oidc->authenticate();
$id=$oidc->requestUserInfo('email');
} catch(Exception $e) {
echo "reauthentication failed.";
exit(0);
}
}
if(!isset($id)) {
echo "could not get login name from oidc session\n";
exit(0);
}
# if we are on the first request from the oidc provider, send a redirect
if(isset($_GET['code'])) {
header("Location: .");
exit(0);
}
} else {
try {
$oidc = new OpenIDConnectClient('https://id.tilde.green/realms/tgci',
'CLIENTID',
'CLIENTSECRET');
$oidc->authenticate();
#$name = $oidc->requestUserInfo('user_id');
} catch (Exception $e) {
echo '<pre>Caught exception: ', $e->getMessage(), "\n";
echo $e->getTraceAsString(), "</pre>\n";
exit(0);
}
$_SESSION['oidc']=$oidc;
if(isset($_GET['code'])) {
header("Location: .");
exit(0);
}
}
1 | <?php // -*-c++-*- |
2 | |
3 | # debug mode, don't do that on a live service |
4 | ini_set('display_errors', 1); |
5 | ini_set('display_startup_errors', 1); |
6 | error_reporting(E_ALL); |
7 | |
8 | require __DIR__ . '/vendor/autoload.php'; |
9 | |
10 | use Jumbojett\OpenIDConnectClient; |
11 | |
12 | session_start(); |
13 | |
14 | if(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 |