Skip to content

Commit 3361e6c

Browse files
authored
Add files via upload
1 parent 3f2b130 commit 3361e6c

File tree

4 files changed

+774
-0
lines changed

4 files changed

+774
-0
lines changed

img/simplesamlphp-sp-demo-app.gif

4.09 MB
Loading
Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
<?php
2+
3+
/**
4+
* SimpleSAMLphp Service Provider (SP) Demo Application
5+
* Version 1.0.0
6+
*
7+
* Published under: https://github.com/disisto/simplesamlphp-wordpressauth
8+
*
9+
* Licensed under MIT
10+
*
11+
* Copyright (c) 2023 Roberto Di Sisto
12+
*
13+
* Permission is hereby granted, free of charge, to any person obtaining a copy
14+
* of this software and associated documentation files (the "Software"), to deal
15+
* in the Software without restriction, including without limitation the rights
16+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17+
* copies of the Software, and to permit persons to whom the Software is
18+
* furnished to do so, subject to the following conditions:
19+
*
20+
* The above copyright notice and this permission notice shall be included in all
21+
* copies or substantial portions of the Software.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29+
* SOFTWARE.
30+
**/
31+
32+
###################################
33+
########## SimpleSAMLphp ##########
34+
###################################
35+
36+
// Define the service provider (SP) authentication source, e.g. "default-sp".
37+
$authSource = 'default-sp';
38+
39+
// Load local SimpleSAMLphp library
40+
$sspAutoload = '/var/simplesamlphp/src/_autoload.php';
41+
42+
// Define URL to download the profile pictures
43+
// Check line 92
44+
45+
46+
if (file_exists($sspAutoload)) {
47+
require_once $sspAutoload;
48+
}
49+
else {
50+
$error = '
51+
<div class="col-md-12 mt-5">
52+
<div class="alert alert-danger" role="alert">
53+
<h4 class="alert-heading">
54+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-exclamation-triangle-fill" viewBox="0 0 16 16">
55+
<path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>
56+
</svg>
57+
Error
58+
</h4>
59+
<p>File not found:</p>
60+
<pre>'.$sspAutoload.'</pre>
61+
<hr>
62+
<p>Unable to load required library</p>
63+
</div>
64+
</div>
65+
';
66+
}
67+
68+
session_start();
69+
// Initialize the SimpleSAMLphp authentication object
70+
if (!isset($error)) {
71+
$auth = new \SimpleSAML\Auth\Simple($authSource);
72+
73+
// Force login
74+
#$auth->requireAuth();
75+
76+
// Check if the user is already authenticated
77+
$loginNeeded = false;
78+
if (!$auth->isAuthenticated()) {
79+
// User is not authenticated
80+
$loginNeeded = true;
81+
} else {
82+
// User is authenticated
83+
$attributes = $auth->getAttributes();
84+
85+
foreach ($attributes as $key => $valueArray) {
86+
${$key} = (!empty($valueArray[0]) ? $valueArray[0] : null);
87+
}
88+
}
89+
90+
// Make sure you restore your own session data
91+
$session = \SimpleSAML\Session::getSessionFromRequest();
92+
$session->cleanup();
93+
session_write_close();
94+
}
95+
96+
###################################
97+
########## SimpleSAMLphp ##########
98+
###################################
99+
100+
$styledOutput = '';
101+
102+
if (!empty($attributes)) {
103+
foreach ($attributes as $key => $valueArray) {
104+
$styledOutput .= '<div class="col-md-12 mt-1"><label class="labels">' . $key . '</label>';
105+
106+
foreach ($valueArray as $value) {
107+
$styledOutput .= '<input type="text" class="form-control" placeholder="[no value]" value="' . htmlspecialchars($value) . '" disabled>';
108+
}
109+
110+
$styledOutput .= '</div>';
111+
}
112+
}
113+
114+
## $profile_photo is an attribute of WordPress plugins that allow saving profile pictures
115+
## locally, instead of loading it from gravatar.com. Don't expect anything special if you
116+
## don't use plugins like 'Ultimate Member' and co.
117+
if (empty($profile_photo)) {
118+
$profile_photo = 'https://secure.gravatar.com/avatar/'.md5($email).'?s=96&d=mm&r=g';
119+
}
120+
else {
121+
// If you use plugins like 'Ultimate Member', paste the correct URL here to make it work.
122+
$profile_photo = 'https://your-domain.tld/wp-content/uploads/ultimatemember/'.$uid.'/'.$profile_photo;
123+
}
124+
125+
if (isset($loginNeeded) && ($loginNeeded === true) ) {
126+
$loginNeeded = '<a class="btn btn-outline-primary" href="'.htmlspecialchars($auth->getLoginURL()).'" role="button">Login</a>';
127+
$loginMessage = '
128+
<div class="col-md-12 mt-5">
129+
<div class="alert alert-warning" role="alert">
130+
<h4 class="alert-heading">Please login</h4>
131+
<p>You must be logged in to get the attributes.</p>
132+
<div class="d-flex justify-content-center"> <!-- Hier wird der Button zentriert -->
133+
<a class="btn btn-primary me-2" href="'.htmlspecialchars($auth->getLoginURL()).'" role="button">Login</a>
134+
</div>
135+
</div>
136+
</div>
137+
';
138+
}
139+
else {
140+
if (!isset($error)) {
141+
$loginNeeded = '<a class="btn btn-outline-primary" href="'.htmlspecialchars($auth->getLogoutURL()).'" role="button">Logout</a>';
142+
}
143+
}
144+
145+
?>
146+
<!doctype html>
147+
<html lang="en" data-bs-theme="auto">
148+
<head><script src="https://getbootstrap.com/docs/5.3/assets/js/color-modes.js"></script>
149+
150+
<meta charset="utf-8">
151+
<meta name="viewport" content="width=device-width, initial-scale=1">
152+
<meta name="author" content="Roberto Di Sisto">
153+
<meta name="description" content="SimpleSAMLphp Wordpress authentication source https://github.com/disisto/simplesamlphp-wordpressauth">
154+
<title>SimpleSAMLphp WordpressAuth</title>
155+
<meta name="theme-color" content="#712cf9">
156+
157+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
158+
159+
<style>
160+
.bi {
161+
vertical-align: -.125em;
162+
fill: currentColor;
163+
}
164+
165+
.labels {
166+
font-size: 13px;
167+
}
168+
169+
pre {
170+
white-space: pre-wrap;
171+
}
172+
</style>
173+
174+
175+
</head>
176+
<body>
177+
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
178+
<symbol id="check2" viewBox="0 0 16 16">
179+
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/>
180+
</symbol>
181+
<symbol id="circle-half" viewBox="0 0 16 16">
182+
<path d="M8 15A7 7 0 1 0 8 1v14zm0 1A8 8 0 1 1 8 0a8 8 0 0 1 0 16z"/>
183+
</symbol>
184+
<symbol id="moon-stars-fill" viewBox="0 0 16 16">
185+
<path d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278z"/>
186+
<path d="M10.794 3.148a.217.217 0 0 1 .412 0l.387 1.162c.173.518.579.924 1.097 1.097l1.162.387a.217.217 0 0 1 0 .412l-1.162.387a1.734 1.734 0 0 0-1.097 1.097l-.387 1.162a.217.217 0 0 1-.412 0l-.387-1.162A1.734 1.734 0 0 0 9.31 6.593l-1.162-.387a.217.217 0 0 1 0-.412l1.162-.387a1.734 1.734 0 0 0 1.097-1.097l.387-1.162zM13.863.099a.145.145 0 0 1 .274 0l.258.774c.115.346.386.617.732.732l.774.258a.145.145 0 0 1 0 .274l-.774.258a1.156 1.156 0 0 0-.732.732l-.258.774a.145.145 0 0 1-.274 0l-.258-.774a1.156 1.156 0 0 0-.732-.732l-.774-.258a.145.145 0 0 1 0-.274l.774-.258c.346-.115.617-.386.732-.732L13.863.1z"/>
187+
</symbol>
188+
<symbol id="sun-fill" viewBox="0 0 16 16">
189+
<path d="M8 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z"/>
190+
</symbol>
191+
<symbol id="person-check" viewBox="0 0 16 16">
192+
<path d="M12.5 16a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Zm1.679-4.493-1.335 2.226a.75.75 0 0 1-1.174.144l-.774-.773a.5.5 0 0 1 .708-.708l.547.548 1.17-1.951a.5.5 0 1 1 .858.514ZM11 5a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM8 7a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z"/>
193+
<path d="M8.256 14a4.474 4.474 0 0 1-.229-1.004H3c.001-.246.154-.986.832-1.664C4.484 10.68 5.711 10 8 10c.26 0 .507.009.74.025.226-.341.496-.65.804-.918C9.077 9.038 8.564 9 8 9c-5 0-6 3-6 4s1 1 1 1h5.256Z"/>
194+
</symbol>
195+
<symbol id="github" viewBox="0 0 16 16">
196+
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"/>
197+
</symbol>
198+
</svg>
199+
200+
<div class="col-lg-8 mx-auto p-4 py-md-5">
201+
<header class="d-flex align-items-center pb-3 mb-5 border-bottom">
202+
<a href="" class="d-flex align-items-center text-body-emphasis text-decoration-none">
203+
<svg class="bi me-sm-1" width="40" height="32"><use xlink:href="#person-check"/></svg>
204+
<span class="fs-4 d-none d-sm-inline me-2">SimpleSAMLphp</span>
205+
<span class="fs-4">WordpressAuth</span>
206+
</a>
207+
208+
<div class="ms-auto d-flex align-items-center">
209+
<?= (isset($loginNeeded) ? $loginNeeded : null); ?>
210+
</div>
211+
212+
<div class="btn-group mx-2">
213+
<button class="btn btn-outline-primary dropdown-toggle d-flex align-items-center"
214+
id="bd-theme"
215+
type="button"
216+
aria-expanded="false"
217+
data-bs-toggle="dropdown"
218+
aria-label="Toggle theme (auto)">
219+
<svg class="bi my-1 theme-icon-active" width="1em" height="1em"><use href="#circle-half"></use></svg>
220+
<span class="visually-hidden" id="bd-theme-text">Toggle theme</span>
221+
</button>
222+
223+
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-theme shadow" aria-labelledby="bd-theme-text">
224+
<li>
225+
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="light" aria-pressed="false">
226+
<svg class="bi me-2 opacity-50 theme-icon" width="1em" height="1em"><use href="#sun-fill"></use></svg>
227+
Light
228+
<svg class="bi ms-auto d-none" width="1em" height="1em"><use href="#check2"></use></svg>
229+
</button>
230+
</li>
231+
<li>
232+
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="dark" aria-pressed="false">
233+
<svg class="bi me-2 opacity-50 theme-icon" width="1em" height="1em"><use href="#moon-stars-fill"></use></svg>
234+
Dark
235+
<svg class="bi ms-auto d-none" width="1em" height="1em"><use href="#check2"></use></svg>
236+
</button>
237+
</li>
238+
<li>
239+
<button type="button" class="dropdown-item d-flex align-items-center active" data-bs-theme-value="auto" aria-pressed="true">
240+
<svg class="bi me-2 opacity-50 theme-icon" width="1em" height="1em"><use href="#circle-half"></use></svg>
241+
Auto
242+
<svg class="bi ms-auto d-none" width="1em" height="1em"><use href="#check2"></use></svg>
243+
</button>
244+
</li>
245+
</ul>
246+
</div>
247+
</header>
248+
249+
<main>
250+
251+
<!-- TAB PILLS-->
252+
<div class="container mt-4">
253+
<div class="row">
254+
<div class="col-md-4"></div>
255+
256+
<div class="col-md-4">
257+
<ul class="nav nav-pills d-flex justify-content-center justify-content-lg-start ps-3" id="myTabs" role="tablist">
258+
<li class="nav-item" role="presentation">
259+
<button class="nav-link active" id="tab-styled-tab" data-bs-toggle="tab" data-bs-target="#tab-styled" type="button" role="tab" aria-controls="tab-styled" aria-selected="true">Styled</button>
260+
</li>
261+
<li class="nav-item" role="presentation">
262+
<button class="nav-link" id="tab-raw-tab" data-bs-toggle="tab" data-bs-target="#tab-raw" type="button" role="tab" aria-controls="tab-raw" aria-selected="false">Raw</button>
263+
</li>
264+
</ul>
265+
</div>
266+
267+
<div class="col-md-4"></div>
268+
</div>
269+
</div>
270+
271+
272+
273+
<!-- TAB CONTENT-->
274+
<div class="tab-content" id="myTabsContent">
275+
<div class="tab-pane fade show active" id="tab-styled" role="tabpanel" aria-labelledby="tab-styled-tab">
276+
<!-- STYLED -->
277+
<div class="container rounded mt-2 mb-5">
278+
279+
<div class="row">
280+
<div class="col-md-4">
281+
<div class="d-flex flex-column align-items-center text-center p-3 py-5">
282+
<img class="rounded-circle mt-5" width="150" alt="Profile Picture" src="<?= $profile_photo; ?>">
283+
<span class="font-weight-bold mt-2"><?= (!empty($display_name) ? $display_name : '[display_name no value]') ?></span>
284+
<span class="text-muted labels"><?= (!empty($email) ? $email : '[email no value]') ?></span>
285+
</div>
286+
</div>
287+
<div class="col-md-5">
288+
<div class="p-3 py-5">
289+
<div class="d-flex justify-content-between align-items-center mb-3">
290+
<h4 class="text-right">Profile Attributes</h4>
291+
</div>
292+
<div class="row mt-2">
293+
<div class="col-md-6"><label class="labels">First Name</label><input type="text" class="form-control" placeholder="[no value]" value="<?= (!empty($first_name) ? $first_name : null) ?>" disabled></div>
294+
<div class="col-md-6"><label class="labels">Last Name</label><input type="text" class="form-control" placeholder="[no value]" value="<?= (!empty($last_name) ? $last_name : null) ?>" disabled></div>
295+
</div>
296+
<div class="row mt-1">
297+
<?= (!empty($error) ? $error : null).
298+
(!empty($loginMessage) ? $loginMessage : null).
299+
$styledOutput; ?>
300+
</div>
301+
</div>
302+
</div>
303+
<div class="col-md-1">
304+
<div class="d-flex flex-column align-items-center text-center p-3 py-5"></div>
305+
</div>
306+
</div>
307+
308+
</div>
309+
<!-- STYLE-->
310+
</div>
311+
<div class="tab-pane fade" id="tab-raw" role="tabpanel" aria-labelledby="tab-raw-tab">
312+
<!-- RAW -->
313+
<div class="container rounded mt-2 mb-5">
314+
315+
<div class="row">
316+
<div class="col-md-2">
317+
</div>
318+
<div class="col-md-7">
319+
<div class="p-3"></div>
320+
<div class="card">
321+
<div class="card-header">
322+
print_r($attributes);
323+
</div>
324+
<div class="card-body bg-dark text-white">
325+
<pre><?php (isset($attributes) ? print_r($attributes) : null ); ?></pre>
326+
</div>
327+
</div>
328+
<?= (!empty($error) ? $error : null).
329+
(!empty($loginMessage) ? $loginMessage : null) ?>
330+
</div>
331+
</div>
332+
<div class="col-md-1">
333+
<div class="d-flex flex-column align-items-center text-center p-3 py-5"></div>
334+
</div>
335+
</div>
336+
337+
</div>
338+
<!-- RAW-->
339+
</div>
340+
341+
342+
</main>
343+
<footer class="pt-5 my-5 text-body-secondary border-top">
344+
&copy; <?= ((date('Y') == '2023') ? date('Y') : '2023-'.date('Y')); ?>
345+
<a href="https://github.com/disisto/simplesamlphp-wordpressauth" title="GitHub" target="_blank" rel="noopener noreferrer nofollow" class="text-muted text-decoration-none">
346+
<svg class="bi" width="16" height="16"><use xlink:href="#github"/></svg>
347+
SimpleSAMLphp WordpressAuth
348+
</a>
349+
</footer>
350+
</div>
351+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm" crossorigin="anonymous"></script>
352+
353+
</body>
354+
</html>

0 commit comments

Comments
 (0)