I’m having issues when I’m trying to save the login access token on the browser’s cookies when I’m using my custom domain attached to my AWS Elastic BeanStalk instance. If I’m accessing it using the instance’s domain (my-custom-domain.aws-region.elasticbeanstalk.com) it’s working fine, but if I try to access it from the custom domain attached to it, it’s not saving it. At this point both domains (instance and custom domain) are not secured (I’m using HTTP).
When sending the cookie, I’m using the following logic on the /login endpoint on the Spring Boot backend:
ResponseCookie cookie = ResponseCookie.from("accessToken", logInDTO.getJwt())
.httpOnly(true)
.secure(false)
.path("/")
.maxAge(1800)
.build();
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set(HttpHeaders.SET_COOKIE, cookie.toString());
Also my CORS configuration looks like this:
CorsConfiguration ccfg = new CorsConfiguration();
ccfg.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://127.0.0.1:3000", "http://www.my-custom-domain.com"));
ccfg.setAllowedMethods(Collections.singletonList("*"));
ccfg.setAllowCredentials(true);
ccfg.setAllowedHeaders(Collections.singletonList("*"));
ccfg.setExposedHeaders(Arrays.asList("Authorization"));
On the frontend I’m using the credentials: ‘include’ read-only property on each request I make (including the login one).
On AWS Route 53 I have a hosted zone for my-custom-domain.com where I have the following record:
- record name: www.my-custom-domain.com
- record type: A
- routing: Simple
- alias: Yes
- Value/Route traffic to: app-name.aws-region.elasticbeanstalk.com
Since there are some workarounds to similar problems, I tried using both .sameSite(“None”) or .domain(“www.my-custom-domain.com”) when I’m creating the cookie object on the backend but it’s still not working and even more, using .sameSite(“None”) prevents saving the cookie even in the Elastic BeanStalk’s instance domain which is working so far.