-
-
Notifications
You must be signed in to change notification settings - Fork 503
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·56 lines (48 loc) · 1.97 KB
/
index.php
File metadata and controls
executable file
·56 lines (48 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* SAMPLE Code to demonstrate how to initiate a SAML Authorization request
*
* When the user visits this URL, the browser will be redirected to the SSO
* IdP with an authorization request. If successful, it will then be
* redirected to the consume URL (specified in settings) with the auth
* details.
*/
session_start();
require_once dirname(__DIR__).'/_toolkit_loader.php';
use OneLogin\Saml2\AuthnRequest;
use OneLogin\Saml2\Settings;
use OneLogin\Saml2\Utils;
/** @var \GuzzleHttp\Psr7\ServerRequest $request */
$request = \GuzzleHttp\Psr7\ServerRequest::fromGlobals();
if (!isset($_SESSION['samlUserdata'])) {
$settings = new Settings();
$authRequest = new AuthnRequest($settings);
$samlRequest = $authRequest->getRequest();
$parameters = array('SAMLRequest' => $samlRequest);
$parameters['RelayState'] = Utils::getSelfURLNoQuery();
$idpData = $settings->getIdPData();
$ssoUrl = $idpData['singleSignOnService']['url'];
return Utils::redirect($ssoUrl, $parameters);
} else {
$html = '';
if (!empty($_SESSION['samlUserdata'])) {
$attributes = $_SESSION['samlUserdata'];
$html .= 'You have the following attributes:<br>';
$html .= '<table><thead><th>Name</th><th>Values</th></thead><tbody>';
foreach ($attributes as $attributeName => $attributeValues) {
$html .= '<tr><td>' . htmlentities($attributeName) . '</td><td><ul>';
foreach ($attributeValues as $attributeValue) {
$html .= '<li>' . htmlentities($attributeValue) . '</li>';
}
$html .= '</ul></td></tr>';
}
$html .= '</tbody></table>';
if (!empty($_SESSION['IdPSessionIndex'])) {
$html .= '<p>The SessionIndex of the IdP is: '.$_SESSION['IdPSessionIndex'].'</p>';
}
} else {
$html .= "<p>You don't have any attribute</p>";
}
$html .= '<p><a href="slo.php">Logout</a></p>';
return new \GuzzleHttp\Psr7\Response(200, [], $html);
}