Skip to content

Instantly share code, notes, and snippets.

@cilf
Last active December 17, 2015 03:48
Show Gist options
  • Save cilf/5545809 to your computer and use it in GitHub Desktop.
Save cilf/5545809 to your computer and use it in GitHub Desktop.
Example of how to use UTEP Single Sign On Service in PHP.
<?php
/**
* Example of how to use UTEP Single Sign On Service.
*
* The only restriction for this to use is that the application
* must run under .utep.edu domain.
* (UTEP SSO page sets cookie which is valid only for .utep.edu)
*
* This code is published under WTFPL.
* Copyright (c) 2013, Marek Polcar <marek.polcar@gmail.com>
*/
/**
* Deleting cookie & redirecting to homepage
*/
if (isset($_GET['logout'])) {
setcookie("MyUTEPCookie", NULL, -3600, "/", ".utep.edu");
header('Location: ?');
exit;
}
if (isset($_GET['login-using-sso'])) {
/**
* The cookie is already set, let's fetch user's data
*/
if (isset($_COOKIE['MyUTEPCookie'])) {
$cookievalue = $_COOKIE['MyUTEPCookie'];
$session = substr($cookievalue, 8, 36);
$salt = substr($cookievalue, 50, 36);
$client = new SoapClient('http://websvs.utep.edu/databaseservices/public/externalsignon.asmx?WSDL');
$parameters = (object) array (
'SessionId' => $session,
'salt' => $salt,
);
$result = $client->GetUser($parameters);
$user = $result->GetUserResult;
/**
* here you can save the user's data into $_SESSION or whatever
*/
/**
* The cookie is not set
* -> redirect to sso page for the user to log in
*/
} else {
// current URI for redirect back from sso page
$uri = ( $_SERVER['HTTPS'] === 'off' ? 'http://' : 'https://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$uriEncoded = urlencode($uri);
header('Location: https://adminapps.utep.edu/externalsso/default.aspx?redirectURL=' . $uriEncoded);
exit;
}
}
?>
<html>
<head>
<title>UTEP Single Sign On Example</title>
</head>
<body>
<?php
/**
* the user is logged in, let's show his data
*/
if(isset($_COOKIE['MyUTEPCookie'])) {
echo "UserName: " . $user->UserName . "<br>\n"
. "FullName: " . $user->FullName . "<br>\n"
. "EmailAddress: " . $user->EmailAddress . "<br><br>\n\n";
// ... and more in $user:
// var_dump($user);
echo '<a href="?logout">logout</a>';
} else {
echo '<a href="?login-using-sso">login using sso</a>';
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment