config.php
<?php/*** The purpose of this central config file is configuring all examples* in one place with minimal work for your working environment* Just configure all the items in this config according to your environment* and rename the file to config.php** PHP Version 5** @file config.php* @category Authentication* @package PhpCAS* @author Joachim Fritschi <jfritschi@freenet.de>* @author Adam Franco <afranco@middlebury.edu>* @license .0 Apache License 2.0* @link */
$phpcas_path = '../../source/';
///
// Basic Config of the phpCAS client //
///
// Full Hostname of your CAS Server
$cas_host = '服务器地址';
// Context of the CAS Server
$cas_context = '/cas';
// Port of your CAS server. Normally for a https server it's 443
$cas_port = 80;
// Path to the ca chain that issued the cas server certificate
$cas_server_ca_cert_path = '/path/to/cachain.pem';
//
// Advanced Config for special purposes //
//
// The "real" hosts of clustered cas server that send SAML logout messages
// Assumes the cas server is load balanced across multiple hosts
$cas_real_hosts = array(ample', ample');
// Client config for cookie hardening
$client_domain = 'localhost';
$client_path = 'phpcas';
$client_secure = false;
$client_httpOnly = false;
$client_lifetime = 0;
// Database config for PGT Storage
$db = 'pgsql:host=localhost;dbname=phpcas';
//$db = 'mysql:host=localhost;dbname=phpcas';
$db_user = 'phpcasuser';
$db_password = 'mysupersecretpass';
$db_table = 'phpcastabel';
$driver_options = '';
///
// End Configuration -- Don't edit below //
///
// Generating the URLS for the local cas example services for proxy testing
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {$curbase = '' . $_SERVER['SERVER_NAME'];
} else {$curbase = '' . $_SERVER['SERVER_NAME'];
}
if ($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {$curbase .= ':' . $_SERVER['SERVER_PORT'];
}
$curdir = dirname($_SERVER['REQUEST_URI']) . "/";
// CAS client nodes for rebroadcasting pgtIou/pgtId and logoutRequest
$rebroadcast_node_1 = '';
$rebroadcast_node_2 = '';
// access to a single service
$serviceUrl = $curbase . $curdir . 'example_service.php';
// access to a second service
$serviceUrl2 = $curbase . $curdir . 'example_service_that_proxies.php';
$pgtBase = preg_quote(preg_replace('/^http:/', 'https:', $curbase . $curdir), '/');
$pgtUrlRegexp = '/^' . $pgtBase . '.*$/';
$cas_url = '' . $cas_host;
if ($cas_port != '443') {$cas_url = $cas_url . ':' . $cas_port;
}
$cas_url = $cas_url . $cas_context;
// Set the session-name to be unique to the current script so that the client script
// doesn't share its session with a proxied script.
// This is just useful when running the example code, but not normally.
session_name('session_for:'. preg_replace('/[^a-z0-9-]/i', '_', basename($_SERVER['SCRIPT_NAME']))
);
// Set an UTF-8 encoding header for internation characters (User attributes)
header('Content-Type: text/html; charset=utf-8');
?>
verify.php
<?php
/*** Example for a simple cas 2.0 client** PHP Version 5** @file example_simple.php* @category Authentication* @package PhpCAS* @author Joachim Fritschi <jfritschi@freenet.de>* @author Adam Franco <afranco@middlebury.edu>* @license .0 Apache License 2.0* @link */
// Load the settings from the central config file
require_once 'config.php';
// Load the CAS lib
require_once 'CAS.php';
// Enable debugging
phpCAS::setDebug();
// Enable verbose error messages. Disable in production!
phpCAS::setVerbose(true);
// Initialize phpCAS
phpCAS::client(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_context);
// For production use set the CA certificate that is the issuer of the cert
// on the CAS server and uncomment the line below
// phpCAS::setCasServerCACert($cas_server_ca_cert_path);
// For quick testing you can disable SSL validation of the CAS server.
// THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION.
// VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL!
phpCAS::setNoCasServerValidation();
// force CAS authentication
phpCAS::forceAuthentication();if (isset($_REQUEST['logout'])) {phpCAS::logout();
}
$account = phpCAS::getAttribute('参数名');
echo $account;
// 或添加成功后的跳转页面
// header("Location:");?>
访问localhost://phpcas/verify.php 会到服务器进行认证,未认证跳转到认证页,认证后跳转到目标页或返回用户信息。
代码需要自定义的部分是中文内容(入门小练习 ok 溜)
本文发布于:2024-01-31 12:04:59,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170667390228392.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |