【问题标题】:How to get username in simplesamlphp saml response using php?如何使用 php 在 simplesamlphp saml 响应中获取用户名?
【发布时间】:2016-02-23 09:46:46
【问题描述】:

我是 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");
    }

     ?>`

【问题讨论】:

    标签: php response saml


    【解决方案1】:

    刚刚找到我的问题的答案。 用户名在 getAuthData() 方法下的 simplesamlphp 中带有 NameID。我会和你分享我的php代码。

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

    【讨论】:

    • 请注意,NameID formats 有几个不同的名称,并非所有名称都是用户友好的名称 - 例如您可能不想在所有情况下都向用户显示 NameID。
    猜你喜欢
    • 2017-06-01
    • 2021-07-20
    • 2023-02-08
    • 1970-01-01
    • 1970-01-01
    • 2019-10-24
    • 2022-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多