title: SimplesamlPHP infinite redirection
body: <p>I'd setup <code>simplesamlphp</code> to my localhost as a 3 different virtual host.</p>
  
  <pre><code>1. http://idp-saml.com
  2. http://sp-saml.com
  3. http://api-saml.com
  </code></pre>
  
  <p>When I tried to connect <code>idp-saml.com</code> using <code>sp-saml.com</code> then it works fine.</p>
  
  <p>Now, I want to integrate it with my own application <code>api-saml.com</code>.</p>
  
  <p>For that, I'd follow the below steps:</p>
  
  <ol>
  <li><p>Create "authsouce" to <code>sp-saml.com</code> on 'authsources.php'.
  <code>
  'sp1' =&gt; array(
          'saml:SP',
          'privatekey' =&gt; 'sp-saml.pem',
          'certificate' =&gt; 'sp-saml.crt',
          'entityID' =&gt; 'http://api-saml.com',
          'idp' =&gt; 'http://idp-saml.com',
      )
  </code></p></li>
  <li><p>Now, go to the <code>Federation</code> page and click on "SP1" metadata and copy <code>SAML 2.0 Metadata XML</code></p></li>
  <li><p>Then go to <code>idp-saml.com</code> and open <code>metadata-converter.php</code> and parse <code>SAML 2.0 Metadata XML</code>.</p></li>
  <li><p>Copy both <code>shib13-sp-remote</code> and <code>saml20-sp-remote</code> to <code>metadata\shib13-sp-remote.php</code> and <code>metadata\saml20-sp-remote.php</code> on <code>idp-saml.com</code> virtual host and I can see <code>api-saml.com</code> under <code>federation</code> tab under <code>SAML 2.0 SP Metadata (Trusted)</code> section.</p></li>
  </ol>
  
  <p><a href="https://www.screencast.com/t/424rmDxRlRfV" rel="nofollow noreferrer">https://www.screencast.com/t/424rmDxRlRfV</a></p>
  
  <ol start="5">
  <li>Now, Go to <code>api-saml.com</code> directory and create <code>index.php</code> and add below code</li>
  </ol>
  
  <p><code>require_once('sp-saml/lib/_autoload.php');</code></p>
  
  <pre><code>$saml_auth = new SimpleSAML_Auth_Simple('sp1');
  
  if ($saml_auth-&gt;isAuthenticated()) {
      $attributes = $saml_auth-&gt;getAttributes();    
      var_dump($attributes);    
  }
  else {
      $saml_auth-&gt;requireAuth();
  }
  </code></pre>
  
  <ol start="6">
  <li>Now, tried to access <code>http://api-saml.com</code> and it goes to <code>idp-saml.com</code> and ask me for login credentials. After adding credentials it does not redirect back me to <code>api-saml.com</code> and behave like infinite redirection. You can see <a href="https://www.screencast.com/t/VGhDHE1j" rel="nofollow noreferrer">https://www.screencast.com/t/VGhDHE1j</a></li>
  </ol>