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: https://github.com/adilos-geekos/angular-jwt-projet

and Spring boot (back-end) code: https://github.com/adilos-geekos/spring-jwt-projet

hello, did you find a solution ?

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

Hello. i

successfulAuthentication:
 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 : 

@Override  
protected void configure(final HttpSecurity http)throws Exception {
http
.authorizeRequests()
.antMatchers("/login", "/actuator/\*\*", "/clients/refresh", "/oauth/token/revokeById/\*\*", "/tokens/\*\*")
.permitAll()
.anyRequest()
.authenticated()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.httpBasic();  
}

Hope it’s helps ! 
Regards.

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

1 Like