2

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

     ?>`
ruvi
  • 109
  • 1
  • 9

1 Answers1

3

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;
ruvi
  • 109
  • 1
  • 9
  • 1
    Be aware that there are several different [NameID formats](http://stackoverflow.com/questions/11693297/what-are-the-different-nameid-format-used-for) and not all of them are user friendly names - e.g. you may not want to display NameID to the user in all cases. – Patrick Feb 26 '16 at 20:57