# Access-Control-Allow-Origin error CORS

**URL:** <https://devforum.okta.com/t/access-control-allow-origin-error-cors/23734>\
**Category:** API\
**Created:** [March 24, 2023, 11:37am UTC](https://devforum.okta.com/t/access-control-allow-origin-error-cors/23734 "2023-03-24T11:37:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rudy.negrini](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rudy.negrini](https://devforum.okta.com/u/rudy.negrini)\
**Post date:** [March 24, 2023, 11:37am UTC](https://devforum.okta.com/t/access-control-allow-origin-error-cors/23734/1 "2023-03-24T11:37:22Z")

</div>

Hi I call api userinfo from ionic 4 app and I received this message:

Access to XMLHttpRequest at ‘https://dev-…okta.com/userinfo’ from origin ‘[http://localhost:8100](http://localhost:8100)’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

In developer console I have already enabled Trusted Origins [http://localhost:8100](http://localhost:8100)

how can I solve this problem?

thanks a lot

---

<div class="post-metadata">

**Author:** ![erik](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@erik](https://devforum.okta.com/u/erik)\
**Post date:** [March 24, 2023, 10:10pm UTC](https://devforum.okta.com/t/access-control-allow-origin-error-cors/23734/2 "2023-03-24T22:10:56Z")

</div>

Hello,

A couple of potential issues,  
In the Admin console you setup this URL for both `Redirect` and `CORS`, not just redirect?  
I don’t know if the URL you typed is a typo but there is no endpoint /userinfo directly off of the domain.  
[See here](https://github.com/okta/okta-aws-cli/issues/74).  
Will either be,

- `${baseUrl}/oauth2/v1/userinfo`
- `${baseUrl}/oauth2/${Authorization_Server_ID}/v1/userinfo`

---

<div class="post-metadata">

**Author:** ![rudy.negrini](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rudy.negrini](https://devforum.okta.com/u/rudy.negrini)\
**Post date:** [March 27, 2023, 10:06am UTC](https://devforum.okta.com/t/access-control-allow-origin-error-cors/23734/3 "2023-03-27T10:06:53Z")

</div>

hello thanks for your reply, i have modified the endpoint as you suggested.

As a first step i call the enpoint  
https://dev-…okta.com/oauth2/default/.well-known/openid-configuration

Next I call the authorisation\_endpoint  
https://dev-…okta.com/oauth2/default/v1/authorize  
with the data

- response\_type (code id\_token token)
- client\_id
- redirect\_uri
- state
- scope
- code\_challenge
- code\_challenge\_method
- nonce

which returns the access\_token

Next I call the userinfo\_endpoint passing the access\_token in the header of the call as the authorisation bearer

However, the service always returns a 401 error why?

Thank you very much

---

<div class="post-metadata">

**Author:** ![erik](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@erik](https://devforum.okta.com/u/erik)\
**Post date:** [March 27, 2023, 11:24pm UTC](https://devforum.okta.com/t/access-control-allow-origin-error-cors/23734/4 "2023-03-27T23:24:26Z")

</div>

Sorry, looks like I provided the incorrect link prior, should be,

> **[OpenID Connect & OAuth 2.0 API | Okta Developer](https://developer.okta.com/docs/reference/api/oidc/#userinfo)**
>
> Find information about the OAuth 2.0 and OpenID Connect endpoints that Okta exposes on its authorization servers.

For userinfo the URL are you using is `https://dev-…okta.com/oauth2/default/v1/userinfo` ?

---

<div class="post-metadata">

**Author:** ![rudy.negrini](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rudy.negrini](https://devforum.okta.com/u/rudy.negrini)\
**Post date:** [March 28, 2023, 7:06am UTC](https://devforum.okta.com/t/access-control-allow-origin-error-cors/23734/5 "2023-03-28T07:06:50Z")

</div>

Yes I also tried using https://dev-…okta.com/oauth2/v1/userinfo but it always returns error 401

---

<div class="post-metadata">

**Author:** ![warren](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@warren](https://devforum.okta.com/u/warren)\
**Post date:** [March 28, 2023, 3:58pm UTC](https://devforum.okta.com/t/access-control-allow-origin-error-cors/23734/6 "2023-03-28T15:58:43Z")

</div>

You might want to check the issuer (“iss”) value in your access token. That will determine what the url for the `/userinfo` endpoint will be.

For example, if your issuer is `https://dev-123.okta.com/oauth2/default` then you would just append `/v1/userinfo` to it to get `https://dev-123.okta.com/oauth2/default/v1/userinfo`.

---

<div class="post-metadata">

**Author:** ![rudy.negrini](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rudy.negrini](https://devforum.okta.com/u/rudy.negrini)\
**Post date:** [March 29, 2023, 7:04am UTC](https://devforum.okta.com/t/access-control-allow-origin-error-cors/23734/7 "2023-03-29T07:04:56Z")

</div>

thank you very much I solved the problem

---

<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:** [March 30, 2023, 7:05am UTC](https://devforum.okta.com/t/access-control-allow-origin-error-cors/23734/8 "2023-03-30T07:05:37Z")

</div>

Closed on March 30, 2023, 7:05am UTC

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