0

i have Web app that has spring boot on the backend and on the front I have react. On my backend I have set up oauth2 and everything is working properly(i mean i get desired data about user, validate the token on https://oauth2.googleapis.com/tokeninfo). The problem is when I am doing axios request from frontend to backend i'm getting and error

enter image description here

localhost:8080/farm im trying to reach with axios. Without oauth2.0 enabled i didnt have any problems with reaching this endpoint.

I was trying to add "Access-Control-Allow-Origin" to the axios request but it didnt solve the problem. I was also trying to add the header after successful login on the backend when i redirect to localhost:3000

hardy6413
  • 11
  • 2
  • 2
    Does this answer your question? [Access to fetch at https://accounts.google.com/o/oauth2/v2/auth has been blocked by CORS](https://stackoverflow.com/questions/72382892/access-to-fetch-at-https-accounts-google-com-o-oauth2-v2-auth-has-been-blocked) Requests to the OAuth authorization endpoint via `axios` do not make sense. – Heiko Theißen Dec 10 '22 at 10:25
  • No, this doesnt answer my question. What i am trying to do is to access backend endpoint which is protected by oauth2.0 login with axios request – hardy6413 Dec 10 '22 at 10:31
  • 2
    Once authenticated (if you have an access token), you can make the request with `axios`, but the prior authentication flow (the logon flow) must happen in a visible browsing context, as explained in the other answer. – Heiko Theißen Dec 10 '22 at 10:41
  • I have finally found a solution for this probem, if anyone encounters similar problem please add withCredentials:true to your axios config like in this similar question https://stackoverflow.com/questions/43002444/make-axios-send-cookies-in-its-requests-automatically . Perhaps my question was unclear and i didn't understand the problem properly, thus thank everyone for help and sorry for the problem – hardy6413 Dec 10 '22 at 15:14

0 Answers0