[module.cas] GET works with URL0=0 with redirection | URL0=1 with pop-up management

This commit is contained in:
xdrm-brackets 2018-03-21 00:41:44 +01:00
parent 46ba44d042
commit 81db5a02c8
3 changed files with 26 additions and 9 deletions

View File

@ -20,14 +20,15 @@ class casController{
/* (1) Authentication callback
*
* GET arguments
*
* @ticket<String> CAS callback @ticket
* @popup_mode<boolean> Whether to manage the popup
* @GET[ticket]<String> CAS callback @ticket
*
* @return headers|body<array> The download content
*
---------------------------------------------------------*/
public static function get($args){
$popup_mode = false;
extract($args);
// login: https://sso.univ-pau.fr/cas/login?service=http://ptut.com:8080/api/v/1.0/cas
@ -54,10 +55,26 @@ class casController{
---------------------------------------------------------*/
/* (1) Global DOWNLOAD data */
$headers = ['Content-Type' => 'text/html; charset=UTF-8' ];
$body_start = "Veuillez patienter...<br>Vous allez être redirigés<script type='text/javascript'>( typeof window.opener.cas_callback === 'function' ) && window.opener.cas_callback(";
$body_end = ");window.close();</script>";
/* (2) Reset SESSION */
/* (2) If @popup_mode */
if( $popup_mode !== 0 ){
$body_start = "Veuillez patienter...<br>Vous allez être redirigés<script type='text/javascript'>( typeof window.opener.cas_callback === 'function' ) && window.opener.cas_callback(";
$body_end = "); window.close();</script>";
/* (3) Else -> redirection */
}else{
$homepage = ($_SERVER['SERVER_NAME'] == 'ptut.com' ) ? 'http' : 'https';
$homepage .= '://'.$_SERVER['HTTP_HOST'].'/home';
$body_start = "Veuillez patienter...<br>Vous allez être redirigés<script type='text/javascript'>console.log(";
$body_end = "); document.location = '$homepage'; </script>";
}
/* (4) Reset SESSION */
$_SESSION['CAS'] = [];
@ -84,7 +101,7 @@ class casController{
---------------------------------------------------------*/
/* (1) Build useful variables */
$service = ($_SERVER['SERVER_NAME'] == 'ptut.com' ) ? 'http' : 'https';
$service .= '://'.$_SERVER['HTTP_HOST'].'/api/v/1.0/cas';
$service .= '://'.$_SERVER['HTTP_HOST'].'/api/v/1.0/cas/'.$popup_mode;
$ticket = urlencode($_GET['ticket']);
$validate_url = "https://sso.univ-pau.fr/cas/serviceValidate?ticket=$ticket&service=$service";

View File

@ -27,7 +27,7 @@
"des": "Authenticatation callback (used by third-party OAuth)",
"per": [],
"par": {
"URL0": { "des": "Whether to manage a popup", "typ": "boolean", "opt": true, "ren": "popup_mode", "def": false }
"URL0": { "des": "Whether to manage a popup", "typ": "id", "opt": true, "ren": "popup_mode", "def": 0 }
},
"opt": { "download": true }
},

View File

@ -10,7 +10,7 @@ gstore.add('popup_click', function(){
gstore.get.popup_opened = true;
/* (3) Open popup */
window.pop = window.open('https://sso.univ-pau.fr/cas/login?service='+window.api.target+'cas', '_blank', 'location=no,height=1024,width=1024,scrollbars=yes,status=no');
window.pop = window.open('https://sso.univ-pau.fr/cas/login?service='+window.api.target+'cas/1', '_blank', 'location=no,height=1024,width=1024,scrollbars=yes,status=no');
/* (4) Clear interval (optional) */
!isNaN(window.popint) && clearInterval(window.popint);