Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get username in simplesamlphp saml response using php?

Tags:

php

response

saml

I'm new to saml, I need to decode saml response using php and get username in it, how can I do it? Here is my index page code

`

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

     ?>`
like image 869
ruvi Avatar asked Jul 12 '26 11:07

ruvi


1 Answers

Just found the answer to my question. Username comes with the NameID in simplesamlphp under the getAuthData() method. I'll share my php code with you.

   $auth_data=$as-> getAuthData();

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

   $username=$name['Value'];
   echo $username;
like image 139
ruvi Avatar answered Jul 15 '26 00:07

ruvi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!