Example Integrations¶
The following are examples for integrating txcasproxy with different web technologies.
Apache + PHP¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | <?php
# txcasproxy PHP integration example.
?>
<html>
<head>
<title></title>
</head>
<body>
<h2>Server Variables</h2>
<pre>
<?php
print htmlspecialchars(print_r($_SERVER, $return=TRUE));
?>
</pre>
<?php
$username = $_SERVER['HTTP_REMOTE_USER'];
if($username)
{
?>
<h2>txcasproxy CAS Authenticated User Info for <strong><?php echo htmlspecialchars($username);?></strong></h2>
<pre>
<?php
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1:9444/$username");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($output, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val)
{
if(is_array($val))
{
echo htmlspecialchars("$key:\n");
}
else
{
echo htmlspecialchars("$key => $val\n");
}
}
?>
</pre>
<?php
}
else
{
?>
<h2>No REMOTE_USER</h2>
<?php
}
?>
</body>
</html>
<?php
?>
|
Full example: proxy-test.php
Serve proxy-test.php from Apache (or some other web server that will server up PHP). Protect the URL with txcasproxy. Browse to the web page to see info about the logged in user and associated attributes.
Example command line:
$ twistd -n casproxy \
-e 'ssl:9443:certKey=/path/to/server.crt.pem:privateKey=/path/to/server.key.pem' \
-c 'https://cas.example.net/login' \
-s 'https://cas.example.net/serviceValidate' \
-p 'http://protected.example.org/' \
-a 'tcp:9444' \
-H 'Remote-User'