# CORS problem with Angular and Spring

**URL:** <https://devforum.okta.com/t/cors-problem-with-angular-and-spring/12903>\
**Category:** Questions\
**Created:** [February 12, 2021, 4:01am UTC](https://devforum.okta.com/t/cors-problem-with-angular-and-spring/12903 "2021-02-12T04:01:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinikasarla](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/srinikasarla/32/2615_2.png) [@srinikasarla](https://devforum.okta.com/u/srinikasarla)\
**Post date:** [February 12, 2021, 4:01am UTC](https://devforum.okta.com/t/cors-problem-with-angular-and-spring/12903/1 "2021-02-12T04:01:21Z")

</div>

Okta, Spring Boot and Angular  
Want to maintain okta authentication in spring boot and want to call API from angular. I have tried couple of options and none of them worked. Authentication flow is working fine when accessed API directly but not from angular. Domain added to trusted origins and enabled CORS as well.

How to solve this CORS error?

`Access to XMLHttpRequest at 'https://dev-13097919.okta.com/oauth2/default/v1/authorize?response_type=code&client_id=0oa5oXXXXXX7i5d6&scope=profile%20email%20openid&state=GCENVmdPeFtQuZOU-P5bZgOWbAA7lPivKwlfVqo4cLc%3D&redirect_uri=http://localhost:8069/cab/authorization-code/callback&nonce=jGzEkEw8ErN5B_Re9kdpD-mAHgYLXn0zeYTe42X4hyU' (redirected from 'http://localhost:8069/cab/api/hello-world') from origin 'http://localhost:8069' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.`

Network calls

 ![CORS Error](https://global.discourse-cdn.com/oktadev/original/2X/0/062db6cffbaca24aa3b09fac7687ccdde293d845.jpeg)

Console errors

 ![CORS Error.jpeg](https://global.discourse-cdn.com/oktadev/original/2X/e/e70f10c30a65830dc73eed91df8a498ad57301f6.png)

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [February 12, 2021, 4:41am UTC](https://devforum.okta.com/t/cors-problem-with-angular-and-spring/12903/2 "2021-02-12T04:41:12Z")

</div>

Just to confirm, is `http://localhost:8069` in your trusted origins? The error message indicates it is not.

---

<div class="post-metadata">

**Author:** ![srinikasarla](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/srinikasarla/32/2615_2.png) [@srinikasarla](https://devforum.okta.com/u/srinikasarla)\
**Post date:** [February 12, 2021, 3:02pm UTC](https://devforum.okta.com/t/cors-problem-with-angular-and-spring/12903/3 "2021-02-12T15:02:27Z")

</div>

Yes, `http://localhost:8069` is my trusted origin and added below code to allow cors  
`registry.addMapping("/**") .allowedOrigins("*") .allowedHeaders("*") .allowedMethods("*")`

---

<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, 2021, 8:34pm UTC](https://devforum.okta.com/t/cors-problem-with-angular-and-spring/12903/4 "2021-02-12T20:34:33Z")

</div>

You cannot make an AJAX request to the authorize endpoint, you MUST redirect to this endpoint instead, as noted in [our documentation](https://developer.okta.com/docs/reference/api/oidc/#authorize)

---

<div class="post-metadata">

**Author:** ![srinikasarla](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/srinikasarla/32/2615_2.png) [@srinikasarla](https://devforum.okta.com/u/srinikasarla)\
**Post date:** [February 12, 2021, 8:41pm UTC](https://devforum.okta.com/t/cors-problem-with-angular-and-spring/12903/5 "2021-02-12T20:41:22Z")

</div>

Thank you, do you have any blog or example for this scenario with jwt and custom authentication manager/provider?

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [March 9, 2021, 5:29pm UTC](https://devforum.okta.com/t/cors-problem-with-angular-and-spring/12903/6 "2021-03-09T17:29:07Z")

</div>

What do you mean by “custom authentication manager/provider?” Are you trying to use a custom authorization server? Or are you trying to do something else?

---

<div class="post-metadata">

**Author:** ![Ganeshkenda](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@Ganeshkenda](https://devforum.okta.com/u/Ganeshkenda)\
**Post date:** [April 6, 2022, 12:29am UTC](https://devforum.okta.com/t/cors-problem-with-angular-and-spring/12903/7 "2022-04-06T00:29:39Z")

</div>

Hi all,  
Is this issue resolved? I am also facing same issue.

Thanks

---

<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:** [February 12, 2024, 9:07pm UTC](https://devforum.okta.com/t/cors-problem-with-angular-and-spring/12903/8 "2024-02-12T21:07:23Z")

</div>

Closed on February 12, 2024, 9:07pm UTC

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