我一直在努力解决这个问题,但似乎无法让它发挥作用。当我调用“phpCas::forceAuthentication”时,我不断收到以下错误。

“没有‘Access-Control-Allow-Origin’标头……”。我添加了以下标题,但它仍然不起作用:
header('Access-Control-Allow-Origin: https://localhost');
在我的后端,我通过以下方式包含 CAS:
require_once Yii::app()->basePath.'/lib/CAS.php';
这产生了一个错误,我解决了从(〜第81行)更改CAS文件夹中的“Autoload.php”:
spl_autoload_register('CAS_autoload');
至
spl_autoload_register('CAS_autoload',true ,true);
它解决了这个问题。因此,在所有这些背景下,这是我试图用来登录 CAS 的代码:
require_once Yii::app()->basePath.'/lib/CAS.php';
...
...
public function actionLogin() {
phpCAS::setNoCasServerValidation(); //don't verify SSL (testing)
$url = Yii::app()->params['casReturnURL'];
phpCAS::setFixedServiceURL ($url); //redirect from cas to this url
phpCAS::forceAuthentication(); //authenticate user
$this->actionIsLoggedInFetch(); //check login status
}
function actionIsLoggedInFetch(){
phpCAS::setNoCasServerValidation(); //don't validate SSL (testing)
$url = Yii::app()->params['casReturnURL']; //return url from CAS
phpCAS::setFixedServiceURL ($url); //set return url
$auth = phpCAS::checkAuthentication(); // check CAS authentication
if ($auth == true) {
$_SESSION['LOGGEDIN'] = true;
$_SESSION['USER'] = phpCas::getUser(); //get currently authenticate user
$return['LOGGEDIN'] = true;
}
else {
$_SESSION['LOGGEDIN'] = false;
$return['LOGGEDIN'] = false;
$_SESSION['USER'] = 'invalid';
}
echo jsonEncodePlusYii($return);
}
public function actionLogout() {
valRequestMethodGet();
phpCAS::setNoCasServerValidation(); //don't verify SSL
$url = Yii::app()->params['casReturnURL'];
phpCAS::logoutWithRedirectService($url); //logout then redirect to url
}
此代码产生上述错误。因此,我还使用 CAS 文件夹附带的“example_gateway.php”进行了测试,它的作用就像一个魅力。我还复制了它生成的 url,当我将它粘贴到浏览器中时,它会让我很好地进入 CAS。它也将我返回到正确的页面。这基本上是该代码,但没有包含 php 文件的 HTML。我在这里做错了什么?Yii 是否会更改标题以防止此调用?对此的任何帮助都会非常有帮助。
更新:经过进一步测试,这仍然是断断续续的。如果我使用:
window.location.href = "/path/to/my/login/function";
它会很好地重定向。另外,如果我设置自己的 xhr 请求,它有时会这样做。但是,但是当我调用注销功能时,我从不重定向……永远。怎么了?这是调试日志。
2C49 .START (2016-02-04 16:23:17) phpCAS-1.3.4 ****************[CAS.php:467]
2C49 .=> phpCAS::client('2.0', 'cas.byu.edu', 443, '/cas') [CasController.php:9]
2C49 .| => CAS_Client::__construct('2.0', false, 'cas.byu.edu', 443, '/cas', true) [CAS.php:359]
2C49 .| <= ''
2C49 .<= ''
2C49 .=> phpCAS::setNoCasServerValidation() [CasController.php:33]
2C49 .| You have configured no validation of the legitimacy of the cas server. This is not recommended for production use. [CAS.php:1617]
2C49 .<= ''
2C49 .=> phpCAS::setFixedServiceURL('https://localhost/welfareManager') [CasController.php:35]
2C49 .<= ''
2C49 .=> phpCAS::forceAuthentication() [CasController.php:36]
2C49 .| => CAS_Client::forceAuthentication() [CAS.php:1078]
2C49 .| | => CAS_Client::isAuthenticated() [Client.php:1249]
2C49 .| | | => CAS_Client::_wasPreviouslyAuthenticated() [Client.php:1362]
2C49 .| | | | no user found [Client.php:1604]
2C49 .| | | <= false
2C49 .| | | no ticket found [Client.php:1463]
2C49 .| | <= false
2C49 .| | => CAS_Client::redirectToCas(false) [Client.php:1258]
2C49 .| | | => CAS_Client::getServerLoginURL(false, false) [Client.php:1625]
2C49 .| | | | => CAS_Client::getURL() [Client.php:342]
2C49 .| | | | <= 'https://localhost/welfareManager'
2C49 .| | | <= 'https://cas.byu.edu/cas/login?service=https%3A%2F%2Flocalhost%2FwelfareManager'
2C49 .| | | Redirect to : https://cas.byu.edu/cas/login?service=https%3A%2F%2Flocalhost%2FwelfareManager [Client.php:1632]
2C49 .| | | exit()
2C49 .| | | -
2C49 .| | -
2C49 .|
如果我打开我的网络日志,这就是我看到的:
它没有重定向我:(。
