首页 > 解决方案 > 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。我还需要做其他事情吗?还是我错过了什么?

标签: phpsingle-sign-onsamlsimplesamlphp

解决方案


在打电话之前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";
}

推荐阅读