# Getting cors issue from jquery code

**URL:** <https://devforum.okta.com/t/getting-cors-issue-from-jquery-code/15502>\
**Category:** OAuth/OIDC\
**Created:** [August 12, 2021, 4:20pm UTC](https://devforum.okta.com/t/getting-cors-issue-from-jquery-code/15502 "2021-08-12T16:20:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepika](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@deepika](https://devforum.okta.com/u/deepika)\
**Post date:** [August 12, 2021, 4:20pm UTC](https://devforum.okta.com/t/getting-cors-issue-from-jquery-code/15502/1 "2021-08-12T16:20:07Z")

</div>

I am getting CORS issue from sharepoint site using Jquery. Below i have mention the code i am using to access okta api. I have enabled CORS origin in OKTA API for my Origin URL

var authClient = new OktaAuth({  
url: "https://\*\*_.oktapreview.com/oauth2/default",  
crossOrigin: true,  
mode: ‘cors’,  
issuer: ‘default’,  
headers: { ‘Access-Control-Allow-Origin’: '_’, ‘Content-Type’:‘application/json’ },  
clientId: “0oataaakuqdfdfdfdfdfdd7”,  
redirectUri: ‘xxx’,  
});  
authClient.signIn({  
username: ‘{abc}’,  
password: ‘{xxx}’  
})

This is what we are getting in browser:

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/2/2e1dbd638c05ddf99d1e000de9e3428e17cd86d6.png)

---

<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:** [August 12, 2021, 4:28pm UTC](https://devforum.okta.com/t/getting-cors-issue-from-jquery-code/15502/2 "2021-08-12T16:28:35Z")

</div>

Does the URL for the CORS error look something like `https:// **.oktapreview.com/oauth2/default/api/v1/authn` or does it look like `https://**.oktapreview.com/api/v1/authn`?

Can you update your ‘url’ to `https://**.oktapreview.com`? This value should match your Okta domain, not the Authorization Server/Issuer you are trying to use.

---

<div class="post-metadata">

**Author:** ![deepika](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@deepika](https://devforum.okta.com/u/deepika)\
**Post date:** [August 13, 2021, 7:56am UTC](https://devforum.okta.com/t/getting-cors-issue-from-jquery-code/15502/3 "2021-08-13T07:56:41Z")

</div>

now i am not getting cors error but getting 401 Authentication failed error

---

<div class="post-metadata">

**Author:** ![deepika](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@deepika](https://devforum.okta.com/u/deepika)\
**Post date:** [August 13, 2021, 2:05pm UTC](https://devforum.okta.com/t/getting-cors-issue-from-jquery-code/15502/5 "2021-08-13T14:05:39Z")

</div>

hi andrea,

thank you for your reply, it help me to resolve my issue. but i am facing one more issue now, hope if you can help me on this.  
I don’t want to use redirect in the api call, is it possible to write API Call without passing redirect URL to get token from okta

---

<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:** [August 13, 2021, 3:19pm UTC](https://devforum.okta.com/t/getting-cors-issue-from-jquery-code/15502/6 "2021-08-13T15:19:04Z")

</div>

Most of the OIDC/OAuth flows involve a browser redirect, but you might want to check out Client Credentials flow (used by machine-to-machine integrations to request tokens with a single back-end call): [Implement authorization by grant type | Okta Developer](https://developer.okta.com/docs/guides/implement-grant-type/clientcreds/main/)

Is this for a machine-to-machine integration, testing, or to get actual user-scoped tokens?

---

<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 8, 2024, 7:08pm UTC](https://devforum.okta.com/t/getting-cors-issue-from-jquery-code/15502/9 "2024-02-08T19:08:05Z")

</div>

Closed on February 8, 2024, 7:08pm UTC


