# Login Stuck in Endless Redirect Loop - PhP - SimpleSAMLPhP

**URL:** <https://devforum.okta.com/t/login-stuck-in-endless-redirect-loop-php-simplesamlphp/3993>\
**Category:** SAML\
**Created:** [January 23, 2019, 1:01am UTC](https://devforum.okta.com/t/login-stuck-in-endless-redirect-loop-php-simplesamlphp/3993 "2019-01-23T01:01:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexRS](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@alexRS](https://devforum.okta.com/u/alexRS)\
**Post date:** [January 23, 2019, 1:01am UTC](https://devforum.okta.com/t/login-stuck-in-endless-redirect-loop-php-simplesamlphp/3993/1 "2019-01-23T01:01:07Z")

</div>

Hello!

I’ve spent the past week installing and configuring SimpleSAMLPhP in my application to set up Okta as the IdP and my app/SimpleSAMLPhP as the SP. I believe I’ve gotten my configuration right, but I’ve ended up in a spot that I’ve seen a few other people on these forums ends up in: an infinite redirect loop. The other situations don’t quite match up perfectly with what I’m experiencing, and I haven’t been able to use the answers there to resolve my issues.

Resources I used in my configuration:  
SimpleSAMLPhP docs  
Okta SimpleSamlPHP Example

I’m working in a local environment and I’ve been able to successfully test my configuration using the SimpleSAMLPhP interface. This app is built using the Yii framework

Okta config:  
SSO Url: [https://localhost/simplesaml/module.php/saml/sp/saml2-acs.php/okta-local](https://localhost/simplesaml/module.php/saml/sp/saml2-acs.php/okta-local)  
(box checked for both recipient and destination URL being the same)  
DestinationURL: [https://localhost/simplesaml/module.php/saml/sp/saml2-acs.php/okta-local](https://localhost/simplesaml/module.php/saml/sp/saml2-acs.php/okta-local)  
DefaultRelayState: [https://localhost/catchokta?saml\_sso=okta-local](https://localhost/catchokta?saml_sso=okta-local)

When I start the IdP-initiated flow, after the IdP (okta) authentication has occurred, a new tab is opened and I am directed to my application:

In my DevTools Network Tab, i watch the following occur once you use the link to your “app” from your Okta home page

GET to a myorg. okta .com/home/STUFF - 302

GET to a myorg. okta .com/app/STUFF - 302

GET to a myorg. okta .com/app/STUFF/sso/saml - 200

_START OF LOOP_

POST to localhost /simplesaml/module.php/saml/sp/saml2-acs.php/okta-local - 303  
this post contain s a SAMLResponse as part of the Form Data

GET to localhost /catchokta?saml\_sso=okta-local - 302

GET to myorg. okta .com/app/STUFF/sso/saml?SAMLRequest=CHARACTERS - 200 OK

_START OF NEXT LOOP_

POST to localhost /simplesaml/module.php/saml/sp/saml2-acs.php/okta-local - 303  
this post contain s a SAMLResponse as part of the Form Data -

At my endpoint /catchokta, I have the following logic (pulled from the login flow of the Okta/PhP example):  
$as = new SimpleSAML\_Auth\_Simple($sp);  
$as-\>requireAuth();  
$user = array(  
‘sp’ =\> $sp,  
‘authed’ =\> $as-\>isAuthenticated(),  
‘idp’ =\> $as-\>getAuthData(‘saml:sp:IdP’),  
‘nameId’ =\> $as-\>getAuthData(‘saml:sp:NameID’)[‘Value’],  
‘attributes’ =\> $as-\>getAttributes(),  
);

the call -\>requireAuth is what’s triggering the redirect loop and the $user= line never gets hit.

Has anyone run into this issue before? Any help or tips would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![alexRS](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@alexRS](https://devforum.okta.com/u/alexRS)\
**Post date:** [January 24, 2019, 11:20pm UTC](https://devforum.okta.com/t/login-stuck-in-endless-redirect-loop-php-simplesamlphp/3993/2 "2019-01-24T23:20:46Z")

</div>

In case anyone runs into this issue later, I haven’t figured it out - I’m still working through it, BUT, I’ve gotten some findings. I’m more and more confident the Okta config is correct, but it’s a mismanagement of session between my application and my SAML library, SimpleSAMLPhP

[https://simplesamlphp.org/docs/stable/simplesamlphp-nostate](https://simplesamlphp.org/docs/stable/simplesamlphp-nostate)

---

<div class="post-metadata">

**Author:** ![ojhaashish135](https://avatars.discourse-cdn.com/v4/letter/o/e95f7d/32.png) [@ojhaashish135](https://devforum.okta.com/u/ojhaashish135)\
**Post date:** [October 29, 2021, 3:20am UTC](https://devforum.okta.com/t/login-stuck-in-endless-redirect-loop-php-simplesamlphp/3993/3 "2021-10-29T03:20:00Z")

</div>

Hi @alexRS, I am trying to do a similar setup on my localhost by making a virtual host, and my calls are stuck as an infinite loop and getting the exact issue you had mentioned. It would be really helpful if you will share how did you resolve this problem?  
Thank you.

---

<div class="post-metadata">

**Author:** ![jwcharp](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@jwcharp](https://devforum.okta.com/u/jwcharp)\
**Post date:** [February 3, 2022, 3:09am UTC](https://devforum.okta.com/t/login-stuck-in-endless-redirect-loop-php-simplesamlphp/3993/4 "2022-02-03T03:09:10Z")

</div>

Any luck on resolving this issue?

I have the same issue. I’ve implement many SPs before via SimpleSAMLPhp.  
Everything works using correctly test via samltest.id

Not sure where I am going wrong with OKTA

---

<div class="post-metadata">

**Author:** ![jwcharp](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@jwcharp](https://devforum.okta.com/u/jwcharp)\
**Post date:** [February 3, 2022, 9:12pm UTC](https://devforum.okta.com/t/login-stuck-in-endless-redirect-loop-php-simplesamlphp/3993/5 "2022-02-03T21:12:36Z")

</div>

Hi found this and was able to get it to work:

> **[GitHub - jpf/okta-simplesamlphp-example: An example PHP application that uses...](https://github.com/jpf/okta-simplesamlphp-example)**
>
> An example PHP application that uses SimpleSAMLphp - GitHub - jpf/okta-simplesamlphp-example: An example PHP application that uses SimpleSAMLphp

The key is in setting the “Default RelayState”, as this is required to make simpleSamlPhp work from Okta’s side.

Please let me know if you have any questions, I can try to help or share code further.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [February 8, 2024, 9:26pm UTC](https://devforum.okta.com/t/login-stuck-in-endless-redirect-loop-php-simplesamlphp/3993/6 "2024-02-08T21:26:56Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
