looking for some solutions? You are welcome.

SOLVED: spring rest api unable to set Set-Cookie

Toumi:

Environment

springBootVersion = '2.1.0.RELEASE'

Linux : 18.01 LTS

Context

I have the current method in controller:

    @PostMapping(value = "")
    public ResponseEntity<String> login(@RequestBody @Valid LoginCredentials loginCredentials) {
        return ResponseEntity.status(HttpStatus.OK)
                .header(HttpHeaders.SET_COOKIE, "Authorization=" + "Bearer " + token)
                .build();
}

and my cors are configured right

    @Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
            .allowedOrigins("*")
            .allowedHeaders("*")
            .allowedMethods("*")
            .allowCredentials(true);
}

I also get on postman that the headers are got right

enter image description here

Still the header set-cookie is not sent.

The same happens when i use angular app to send the request with

    return this.http.post(this.LOGIN_URL, loginCred, {withCredentials: true});

As you see, with credentials is set to true. still I do not get my Set-cookie header.

Question

How can I have my header on the frontend (Angular or postman) ?



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent