How to prevent Spring security login redirection 302 after login - angular ?!

hey all, i always get 302 response code instead of JSON response (200 OK), when i try to login using angular as a front-end and spring boot JWT as a back-end, is there any plausible way to stop spring security from redirecting my http request, after a successful authentication, and btw i’m using angular 7 HttpClient to send Http Request to Spring boot.i’ve tried all solutions on the web, but unfortunately none of them is working !!!

login is working and authorization token is sent by the backend server Spring Boot “localhost:5454/login” along with a redirection status code 302. 

here is angular (front-end) code:

and Spring boot (back-end) code:

hello, did you find a solution ?

we watched the same tutorial and I’m having the same problem …

Hello. i

 at the end of this function override, you call the parent method,
 that of Spring Security, it verifies whether the authentication works or not. and as authentication was not done with Spring Security, it makes a redirect to the welcome.

So you juste need to remove the last line in your override

I don’t known if you are still on this issue but I’ve solved it by replacing .formLogin() with .httpBasic() in my  WebSecurityConfigurerAdapter. 

So my security config looks like this : 

protected void configure(final HttpSecurity http)throws Exception {
.antMatchers("/login", "/actuator/\*\*", "/clients/refresh", "/oauth/token/revokeById/\*\*", "/tokens/\*\*")

Hope it’s helps ! 

@lhenri Your suggestion worked. I have tried so many things, but finally adding httpBasic() to the config worked perfectly.

1 Like