Getting cors issue from jquery code

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:

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.

1 Like

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

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

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

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