mirror of
https://github.com/pgmr3/synologySsoClientExamplePage.git
synced 2025-12-12 21:15:48 +01:00
150 lines
4.9 KiB
HTML
150 lines
4.9 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="de">
|
||
<head>
|
||
<!--
|
||
// ------------------------------------------------------------------------------
|
||
//
|
||
// © Copyright (с) 2023 License: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
|
||
// author: https://github.com/pgmr3
|
||
// ------------------------------------------------------------------------------
|
||
-->
|
||
<meta charset="utf-8">
|
||
<title>Server tools</title>
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<meta name="description" content="">
|
||
<meta name="author" content="https://github.com/pgmr3">
|
||
<meta name="copyright" content="https://www.gnu.org/licenses/gpl-3.0.html" />
|
||
<script src="https://sso-yourdomain.com/webman/sso/synoSSO-1.0.0.js"></script>
|
||
</head>
|
||
|
||
<body>
|
||
<div class="container">
|
||
<div class="form-signin">
|
||
<h1 class="form-signin-heading">Server tools</h1>
|
||
<h2 class="form-signin-heading" >Please sign in / sign out / menu</h2>
|
||
<button id="login-button" >SSO sign in</button>
|
||
<button id="logout-button">sign out</button>
|
||
<button id="anwendung-button" onclick="window.location.href = '/my/'" >menu</button>
|
||
</div>
|
||
</div>
|
||
</body>
|
||
|
||
<script src="../js/myLoginScript.js" type="text/javascript"></script>
|
||
<script>
|
||
// globals
|
||
var $token = "";
|
||
var Xlogedin = true;
|
||
Visibility(false, false); //default für Sichtbarkeit der Anzeigeelemente
|
||
//Visibility(true, true); //test alle buttons anzeigen
|
||
|
||
//synology SSO server init
|
||
SYNOSSO.init({
|
||
oauthserver_url: 'https://sso-yourdomain.com', //synology server with sso and dsm, same as config.php
|
||
app_id: 'eb3df56d6f3f11914eb6514c978346fX', // App ID , same as config.php
|
||
redirect_uri: 'https://yourpagedomain.com', //redirect URI not realy used, same as config.php
|
||
// ldap_baseDN: 'dc=sso-domain,dc=com', //necessary if more than one domain in the ldap, same as config.php
|
||
// domain_name: 'sso-domain.com', //necessary if more than one domain in the ldap, same as config.php
|
||
callback: authCallback
|
||
})
|
||
|
||
//sso Login execute callback
|
||
function authCallback(response){
|
||
console.log("authCallback Start");
|
||
const logedin = false;
|
||
if('not_login' === response.status) { //user not login
|
||
console.log (response.status);
|
||
}
|
||
else if('login' === response.status) {
|
||
console.log (response.status);
|
||
console.log (response.access_token);
|
||
//alert("access_token: "+ response.access_token);//test
|
||
$token = response.access_token; //Pass sso_accesstoken for doTestLogedin()
|
||
doTestLogedin(onComplete, $token);
|
||
}
|
||
else {
|
||
console.log (response);
|
||
}
|
||
}
|
||
|
||
//sign in button
|
||
var login_button = document.getElementById("login-button");
|
||
login_button.addEventListener('click' , SYNOSSO.login);
|
||
|
||
// sign out event function is triggert
|
||
var myEventLogOut = function() {
|
||
//alert("myEventLogOut start");//test
|
||
console.log("myEventLogOut");
|
||
SYNOSSO.logout({
|
||
callback: logoutCallback
|
||
});
|
||
//alert("myEventLogOut 2");//Test
|
||
|
||
// since there is no response from SSYNOSSO.logout the following comes
|
||
//let Xin =
|
||
doTestLogedin(onComplete ,null ,$startLogout=true).then ((data) => {
|
||
//console.log(data); //hier undefined, da asyncron
|
||
//alert("myEventLogOut fetch response json in console");//test
|
||
})
|
||
.catch(console.log);
|
||
|
||
//Visibility(!Xin, Xin);
|
||
//window.location.href = ("/"); // clear history not
|
||
window.location.replace("/"); // clear history
|
||
};
|
||
|
||
//callback von SYNOSSO.logout - will NOT fire!
|
||
function logoutCallback(response){
|
||
console.log("logoutCallback");
|
||
if(response) {
|
||
console.log (response);
|
||
//alert("logout resonse in console");
|
||
logedin = false;
|
||
}
|
||
}
|
||
|
||
//logout button
|
||
var logout_button = document.getElementById("logout-button");
|
||
if(logout_button !== null) logout_button.addEventListener('click' , myEventLogOut, false);
|
||
|
||
//menu button
|
||
var menu_button = document.getElementById("menu-button");
|
||
if(menu_button !== null) menu_button.addEventListener('click' , myEventMenu, false);
|
||
var myEventMenu= function() {
|
||
//alert("menu 2");//Test
|
||
window.location.replace("/my/");
|
||
}
|
||
|
||
//Visibility of the buttons
|
||
function Visibility(login=false, logout=false) {
|
||
var logout;
|
||
var login;
|
||
if (logout) {
|
||
document.getElementById("login-button").style.visibility = "visible";
|
||
} else {
|
||
document.getElementById("login-button").style.visibility = "hidden";
|
||
}
|
||
if (login){
|
||
document.getElementById("logout-button").style.visibility = "visible";
|
||
document.getElementById("anwendung-button").style.visibility = "visible";
|
||
} else {
|
||
document.getElementById("logout-button").style.visibility = "hidden";
|
||
document.getElementById("anwendung-button").style.visibility = "hidden";
|
||
}
|
||
}
|
||
|
||
//callback doTestLogedin()
|
||
function onComplete(logedin){ // When the check loggedin completes, do this
|
||
console.log("loggedin: "+ logedin);
|
||
Visibility(logedin, !logedin);
|
||
Xlogedin = logedin; //global
|
||
//alert(logedin);//test
|
||
}
|
||
|
||
//Session expired? query cyclically
|
||
window.setInterval(function () {
|
||
if (Xlogedin) {
|
||
doTestLogedin(onComplete);
|
||
}
|
||
}, 1000); //milli seconds
|
||
|
||
</script> |