lspil / full_stack_oauth2

58 stars 39 forks source link

CORS Problem with Angular App #3

Open simasch opened 1 year ago

simasch commented 1 year ago

I tried the Angular app and when I access http://localhost:3000/ I get:

auth:1 Access to XMLHttpRequest at 'http://localhost:8080/oauth2/token?client_id=client&redirect_uri=http://127.0.0.1:3000/authorized&grant_type=authorization_code&code=&code_verifier=qPsH306-ZDDaOE8DFzVn05TkN3ZZoVmI_6x4LsVglQI' 
from origin 'http://localhost:3000' 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.
pezhmantp commented 1 year ago

The problem is that, CORS distinguishes between localhost and 127.0.01, so you have to add both of them to the CORSCustomizer class in spring like this: cc.setAllowedOrigins(List.of("http://localhost:3000","http://127.0.0.1:3000"));