如何使用 php 在 simplesamlphp saml 响应中获取用户名?

How to get username in simplesamlphp saml response using php?

我是 saml 新手,我需要使用 php 解码 saml 响应并在其中获取用户名,我该怎么做?这是我的索引页面代码

`

 require_once('/var/simplesamlphp/lib/_autoload.php');

 $as = new SimpleSAML_Auth_Simple('default-sp');
 $as->requireAuth();
 $attributes = $as->getAttributes();
 print_r($attributes);

 if(array_key_exists('http://exm/claims/role', $attributes)) {

 }
     $exp_atr=  explode(",", $attributes['http://exm/claims/role'][0]);


   if (in_array("admin_group", $exp_atr)) {
   header("location:index_admin.php");
    }
   else {

    header("location:index_others.php");
    }

     ?>`

刚刚找到我的问题的答案。 username在getAuthData()方法下的simplesamlphp中带有NameID。我将与您分享我的 php 代码。

   $auth_data=$as-> getAuthData();

   $name=$as-> getAuthData("saml:sp:NameID");
   $name['Value']; 

   $username=$name['Value'];
   echo $username;