Last active
August 29, 2015 14:07
-
-
Save mkrogh/58afbaa55056ebe214b7 to your computer and use it in GitHub Desktop.
SimpleSAMLphp and jsConnect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-type: application/javascript'); | |
require_once('../../lib/_autoload.php'); | |
require_once dirname(__FILE__).'/functions.jsconnect.php'; | |
$clientID = "saml-login"; | |
$secret = "TOP_SECRET!"; | |
$as = new SimpleSAML_Auth_Simple('default-sp'); | |
$as-> requireAuth(); | |
$attributes = $as->getAttributes(); | |
$user = array(); | |
if ($as->isAuthenticated()) { | |
//TODO: Use DisplayName over cn? | |
$username = $attributes['cn'][0]; | |
$user['uniqueid'] = implode($attributes['eduPersonTargetedID']); | |
$user['name'] = orDefault($username, "Default user"); | |
$user['email'] = $attributes['mail'][0]; | |
$user['photourl'] = ''; | |
} | |
function orDefault($var, $default) { | |
if(empty($var)) { | |
return $default; | |
}else{ | |
return $var; | |
} | |
} | |
//if set to false it will not sign the response | |
$secure = "sha256"; | |
WriteJsConnect($user, $_GET, $clientID, $secret, $secure); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('../../lib/_autoload.php'); | |
session_start(); | |
if ( !isset( $_SESSION["orgURL"] ) ) { | |
$_SESSION["orgURL"] = $_SERVER["HTTP_REFERER"]; | |
} | |
$as = new SimpleSAML_Auth_Simple('default-sp'); | |
$as-> requireAuth(); | |
if ($as->isAuthenticated()) { | |
$url = redirectURL($_SESSION['orgURL']); | |
unset($_SESSION['orgURL']); | |
header('Location: ' . $url); | |
} | |
function redirectURL($referal) { | |
if (empty($referal)) { | |
$referal = "/"; | |
} | |
$page = parse_url($referal); | |
$query = explode("&", $page["query"]); | |
$target = "/"; | |
foreach ($query as $part) { | |
if (preg_match("/^p=/", $part)) { | |
$target = explode("=", $part)[1]; | |
} | |
} | |
$target = urldecode($target); | |
//make sure the client_id is correct. | |
return "/?p=/entry/jsconnect&client_id=saml-login&Target=" . urlencode($target); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment