# Log into React SPA and then SSO in ASP.NET Core app using OIDC

**URL:** <https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157>\
**Category:** Questions\
**Created:** [September 15, 2021, 6:10pm UTC](https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157 "2021-09-15T18:10:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![punchwalk](https://avatars.discourse-cdn.com/v4/letter/p/71c47a/32.png) [@punchwalk](https://devforum.okta.com/u/punchwalk)\
**Post date:** [September 15, 2021, 6:10pm UTC](https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157/1 "2021-09-15T18:10:18Z")

</div>

I have an [ASP.NET](http://ASP.NET) Core Razor Pages web app that uses the Authorization Code flow and Okta sign-in widget. I’m in the process of migrating to a React SPA with okta-auth-js (with PKCE). The migration will take a few months, and I’d like to allow users who log onto the React SPA to use some sort of SSO to log onto the [ASP.NET](http://ASP.NET) Core app to access views that we haven’t migrated yet.

The [ASP.NET](http://ASP.NET) Core app and React SPA use the same authorization server but different Okta Applications (client ids).

Can anyone give me some pointers on whether this is possible and, if so, how to get started?

---

<div class="post-metadata">

**Author:** ![Lijia](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/lijia/32/2295_2.png) [@Lijia](https://devforum.okta.com/u/Lijia)\
**Post date:** [September 15, 2021, 9:59pm UTC](https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157/2 "2021-09-15T21:59:42Z")

</div>

@punchwalk Hi, you may need refer the doc of  
[https://developer.okta.com/code/react/okta\_react\_sign-in\_widget/#config](https://developer.okta.com/code/react/okta_react_sign-in_widget/#config)  
For react, you need to take a look at this sdk.  
[https://developer.okta.com/code/javascript/okta\_sign-in\_widget/#using-with-okta-sdks](https://developer.okta.com/code/javascript/okta_sign-in_widget/#using-with-okta-sdks)  
If you want the new project using the old app, try link it to the old app and use the old configuration such as client\_id, redirect uri.

---

<div class="post-metadata">

**Author:** ![punchwalk](https://avatars.discourse-cdn.com/v4/letter/p/71c47a/32.png) [@punchwalk](https://devforum.okta.com/u/punchwalk)\
**Post date:** [September 15, 2021, 11:05pm UTC](https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157/3 "2021-09-15T23:05:46Z")

</div>

Thanks for the reply. Unless I am mistaken, the new project cannot use the old project’s Okta application, as we want to use PKCE in accordance with security best practices, and the old app wasn’t configured to use it.

---

<div class="post-metadata">

**Author:** ![Lijia](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/lijia/32/2295_2.png) [@Lijia](https://devforum.okta.com/u/Lijia)\
**Post date:** [September 15, 2021, 11:28pm UTC](https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157/4 "2021-09-15T23:28:14Z")

</div>

@punchwalk Then you probably need to configure the new application and refer the doc of react sdk I sent you.

---

<div class="post-metadata">

**Author:** ![punchwalk](https://avatars.discourse-cdn.com/v4/letter/p/71c47a/32.png) [@punchwalk](https://devforum.okta.com/u/punchwalk)\
**Post date:** [September 16, 2021, 12:20pm UTC](https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157/5 "2021-09-16T12:20:40Z")

</div>

From the reading the linked article, it’s not clear how using the sign-in widget would solve this problem. Can you please elaborate?

---

<div class="post-metadata">

**Author:** ![Lijia](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/lijia/32/2295_2.png) [@Lijia](https://devforum.okta.com/u/Lijia)\
**Post date:** [September 16, 2021, 6:06pm UTC](https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157/6 "2021-09-16T18:06:21Z")

</div>

@punchwalk Did you try this react sdk? [Okta Sign-In Widget Guide | Okta Developer](https://developer.okta.com/code/javascript/okta_sign-in_widget/#react)  
What is your old application type?

---

<div class="post-metadata">

**Author:** ![punchwalk](https://avatars.discourse-cdn.com/v4/letter/p/71c47a/32.png) [@punchwalk](https://devforum.okta.com/u/punchwalk)\
**Post date:** [September 20, 2021, 8:10pm UTC](https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157/7 "2021-09-20T20:10:43Z")

</div>

I got our [ASP.NET](http://ASP.NET) Core app working with the same Okta app as the React app (using OIDC with Code+PKCE).

We use the sign-in widget on the [ASP.NET](http://ASP.NET) Core app. I logged into the React app, then clicked a link that app that points to a secured page on the [ASP.NET](http://ASP.NET) Core app (going from React app to the [ASP.NET](http://ASP.NET) Core app is the prevailing use case and therefore what we’ll need to support). The [ASP.NET](http://ASP.NET) Core app did not detect my existing session with the React app and required me to login again. Both apps are on the same domain and I confirmed that they can be both see each other’s cookies. But I’m clearly missing something and am not sure what else to try.

---

<div class="post-metadata">

**Author:** ![terence.mcdevitt](https://avatars.discourse-cdn.com/v4/letter/t/ba8739/32.png) [@terence.mcdevitt](https://devforum.okta.com/u/terence.mcdevitt)\
**Post date:** [June 4, 2022, 4:14pm UTC](https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157/8 "2022-06-04T16:14:07Z")

</div>

@punchwalk - did you ever get this resolved? We’re trying to do something similar with the embedded sign-in widget (via OIDC) and another SAML-based app. Both use the same Okta instance but when we log in via the widget, then hit the SAML app directly, it doesn’t see our Okta session so the user is asked to authenticate again.  
If we do this in the reverse order, it works fine.

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [June 10, 2022, 9:49pm UTC](https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157/9 "2022-06-10T21:49:50Z")

</div>

You likely will want to add some logic to detect the existing Okta session and not render the widget if the user is already logged into Okta.

For example, you can use the [session.exists()](https://github.com/okta/okta-auth-js#sessionexists) method to check if the app can see the Okta session cookie (set on the Okta domain). If there is one, you can call [getWithoutPrompt](https://github.com/okta/okta-auth-js#tokengetwithoutpromptoptions) to trigger an /authorize request in an iframe to get log the user in.

Of course, if your application is NOT on the same domain as your Okta org, you can run into 3rd party cookie issues. In which case, you can, if you suspect the user has a valid session, simply trigger the /authorize request and redirect the user back tot he Okta domain where the session cookie can be checked using [getWithRedirect](https://github.com/okta/okta-auth-js#tokengetwithredirectoptions). As long as the cookie is still around/user’s Okta session is still valid, they won’t need to re-authenticate and will be sent straight back to the OIDC application.

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [February 12, 2024, 7:54pm UTC](https://devforum.okta.com/t/log-into-react-spa-and-then-sso-in-asp-net-core-app-using-oidc/16157/10 "2024-02-12T19:54:56Z")

</div>

Closed on February 12, 2024, 7:54pm UTC


