# Okta CORS Issue? Works Incognito doesn't work outside of Incognito?

**URL:** <https://devforum.okta.com/t/okta-cors-issue-works-incognito-doesnt-work-outside-of-incognito/3569>\
**Category:** Questions\
**Tags:** cors\
**Created:** [December 6, 2018, 12:37pm UTC](https://devforum.okta.com/t/okta-cors-issue-works-incognito-doesnt-work-outside-of-incognito/3569 "2018-12-06T12:37:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkwyche](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@mkwyche](https://devforum.okta.com/u/mkwyche)\
**Post date:** [December 6, 2018, 12:37pm UTC](https://devforum.okta.com/t/okta-cors-issue-works-incognito-doesnt-work-outside-of-incognito/3569/1 "2018-12-06T12:37:34Z")

</div>

Hi,

I’m hoping someone can help me figure out why I have a CORS issue for one of my `urls` when I’m in a chrome. The odd this is that the login works just fine when I open up an `incognito` browser and try the same login. See gif below for an example.

![out](https://global.discourse-cdn.com/oktadev/original/1X/d7091b1fe79230d7a6ddb063fc1fbfaab0e2ec43.gif)

Here is the actual error:

 ![48%20AM](https://global.discourse-cdn.com/oktadev/original/1X/4efffd955e85d7f4335127da7dc6c035e83167c1.png)

I’m using the `okta-auth-js` library and have followed the instructions [here](https://developer.okta.com/code/javascript/okta_auth_sdk). Code snippet for my login action is here:

> export const oktaLogin = (username, password) =\> {  
> // Attempt to retrieve ID Token from Token Manager  
> // Example: [Auth JS fundamentals | Okta Developer](https://developer.okta.com/code/javascript/okta_auth_sdk)  
> return async (dispatch) =\> {  
> try {  
> let tokenResponse = await oktaClient.tokenManager.get(“idToken”);  
> let idToken, oktaId;  
> // Token comes back if not expired  
> if (tokenResponse) {  
> // Current token is still fine just reuse  
> LOGGER.info(`Welcome back ${tokenResponse.claims.email}`);  
> idToken = tokenResponse[“idToken”];  
> oktaId = tokenResponse.claims.sub;  
> } else {  
> dispatch({ type: types.RESET\_AUTH });  
> dispatch(auth\_user\_request());  
> // Sign user in with okta  
> let signIn = await oktaClient.signIn({ username, password });  
> // TODO: Figure out if I should be setting this sessionToken  
> // [GitHub - okta/okta-auth-js: The official js wrapper around Okta's auth API](https://github.com/okta/okta-auth-js#sessionsetcookieandredirectsessiontoken-redirecturi)  
> // Get idToken from okta  
> // oktaClient.session.setCookieAndRedirect(signIn.sessionToken)  
> let tokenOrTokens = await oktaClient.token.getWithoutPrompt({  
> sessionToken: signIn.sessionToken,  
> responseType: [“id\_token”],  
> scopes: [“openid”, “email”, “profile”]  
> });
> 
> ```
> // Add token to axios
> tokenResponse = tokenOrTokens[0];
> idToken = tokenResponse["idToken"];
> oktaId = tokenResponse.claims.sub;
> }
> axios.defaults.headers.common["Authorization"] = idToken;
> 
> // Get user
> let user = await dispatch(fetchLoginByOktaId(oktaId));
> let userId = user.user_id;
> 
> let response = await fetchUserAccessAndGroups(userId);
> let routeData = processApprovedRoutes(
> response.access,
> response.protected
> );
> 
> // Set up cookies
> cookies.set("token", idToken, { path: "/" });
> cookies.set("username", user.username.trim(), { path: "/" });
> 
> // Add token to tokenManager
> oktaClient.tokenManager.add("idToken", tokenResponse);
> dispatch(auth_user_success(user, routeData, response.groups));
> dispatch(push("/"));
> return Promise.resolve("Successfully logged in");
> } catch (err) {
> LOGGER.error(err);
> dispatch(auth_user_error(err));
> return Promise.reject(err);
> }
> 
> ```
> 
> };  
> };

---

<div class="post-metadata">

**Author:** ![mkwyche](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@mkwyche](https://devforum.okta.com/u/mkwyche)\
**Post date:** [December 6, 2018, 12:47pm UTC](https://devforum.okta.com/t/okta-cors-issue-works-incognito-doesnt-work-outside-of-incognito/3569/2 "2018-12-06T12:47:58Z")

</div>

Update: This works fine on my phone as well without needing to have an incognito browser.

---

<div class="post-metadata">

**Author:** ![tom](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/tom/32/24_2.png) [@tom](https://devforum.okta.com/u/tom)\
**Post date:** [December 11, 2018, 8:44pm UTC](https://devforum.okta.com/t/okta-cors-issue-works-incognito-doesnt-work-outside-of-incognito/3569/3 "2018-12-11T20:44:10Z")

</div>

were you doing some sort of development on your desktop? Like, accessing the keys endpoint from another origin?

---

<div class="post-metadata">

**Author:** ![mkwyche](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@mkwyche](https://devforum.okta.com/u/mkwyche)\
**Post date:** [December 11, 2018, 10:30pm UTC](https://devforum.okta.com/t/okta-cors-issue-works-incognito-doesnt-work-outside-of-incognito/3569/4 "2018-12-11T22:30:28Z")

</div>

Thanks for the reply. Yes. I was doing dev on my local box. Tried closing all my browsers & still was getting the error without going incognito.

---

<div class="post-metadata">

**Author:** ![tom](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/tom/32/24_2.png) [@tom](https://devforum.okta.com/u/tom)\
**Post date:** [December 12, 2018, 5:22pm UTC](https://devforum.okta.com/t/okta-cors-issue-works-incognito-doesnt-work-outside-of-incognito/3569/5 "2018-12-12T17:22:30Z")

</div>

I’m pretty sure what is happening here is the browser cached the `/keys` options call for CORS, and the cached value in the wrong domain. Running in incognito obviously will resolve it, but I would be willing to bet, clearing cache will do the same.

This is a known issue (code is done, should be released in the next week, unless there is any unforeseen circumstances), but shouldn’t impact any customers / clients of yours.

We are changing the caching headers so the browser doesn’t incorrectly cache for the wrong domain.

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![mkwyche](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@mkwyche](https://devforum.okta.com/u/mkwyche)\
**Post date:** [December 12, 2018, 6:01pm UTC](https://devforum.okta.com/t/okta-cors-issue-works-incognito-doesnt-work-outside-of-incognito/3569/6 "2018-12-12T18:01:12Z")

</div>

Thanks that makes sense and yes everyone else I had log in had no issues.

To get the fix all I’ll need to do is update to the latest version of [Okta Auth JS](https://github.com/okta/okta-auth-js) when it’s released?

---

<div class="post-metadata">

**Author:** ![tom](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/tom/32/24_2.png) [@tom](https://devforum.okta.com/u/tom)\
**Post date:** [December 12, 2018, 7:05pm UTC](https://devforum.okta.com/t/okta-cors-issue-works-incognito-doesnt-work-outside-of-incognito/3569/7 "2018-12-12T19:05:22Z")

</div>

It is a server side fix, once we start returning the right caching headers, you may need to clear your cache one more time and that should be it!

---

<div class="post-metadata">

**Author:** ![mkwyche](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@mkwyche](https://devforum.okta.com/u/mkwyche)\
**Post date:** [December 12, 2018, 7:19pm UTC](https://devforum.okta.com/t/okta-cors-issue-works-incognito-doesnt-work-outside-of-incognito/3569/8 "2018-12-12T19:19:59Z")

</div>

😃 even better. Thanks again for the support.

---

<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:** [January 13, 2024, 12:13am UTC](https://devforum.okta.com/t/okta-cors-issue-works-incognito-doesnt-work-outside-of-incognito/3569/9 "2024-01-13T00:13:59Z")

</div>

Closed on January 13, 2024, 12:13am UTC

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