php - simpleSamlPHP isAuthenticated 总是返回 false
问题描述
我刚开始使用 simplesamlPHP 进行开发。我安装了 simpleSamlPhp,并按照 https://simplesamlphp.org/docs/development/simplesamlphp-sp-api中给出的步骤将我的 php 应用程序与 simpleSAMLPhp 集成,我正在使用文档中给出的 simpleSaml API。
下面是代码:
require_once('/var/simplesamlphp/lib/_autoload.php');
$auth = new \SimpleSAML\Auth\Simple('default-sp');
if($auth->isAuthenticated()){
$attributes = $auth->getAttributes();
}else{
echo "Not authenticated";
$auth->requireAuth();
}
$auth->isAuthenticated() 总是返回 false。我还需要做其他事情吗?还是我错过了什么?
解决方案
在打电话之前isAuthenticated()
,你需要打电话requireAuth()
。这个想法是您请求对实体进行身份验证,然后您可以检查用户是否经过身份验证。
require_once('/var/simplesamlphp/lib/_autoload.php');
$auth = new \SimpleSAML\Auth\Simple('default-sp');
$auth->requireAuth();
if($auth->isAuthenticated()){
$attributes = $auth->getAttributes();
}else{
echo "Not authenticated";
}
推荐阅读
- python - 检查输入时出现 Keras 错误:预期 input_4 的形状为 (299, 299, 3) 但得到的数组的形状为 (64, 64, 3)
- sudo - 什么是 sudo chmod -R 775
- powershell - Powershell lambda 范围
- vba - 将使用 Access 表单选择的文件附加到 Outlook 电子邮件
- regex - 如何使用前缀从文件名中删除前导数字?
- android - 如何在回收站视图中获取某些编辑文本的价值?
- virtualbox - 如何在 VirtualBox 中的主机 (Mac OS) 和来宾 (Fedora Server) 之间创建共享文件夹?
- java - 在java中的方法非静态时调用对象
- javascript - 在 ms 团队选项卡中找出两个聊天参与者 (javascript)
- mysql - 具有别名的 MySQL SELECT 查询在 MySQL 5.7.28 中不起作用