Cześć, spotkałem się z dziwną sytuacją której nie mogę zrozumieć. Stworzyłem implementację JWT. W przypadku wykorzystania React i axiosa mogę dostać się do endpointu logowania podać poprawne dane i otrzymać token. Problem pojawia się w przypadku kiedy używam Angulara. Zapytanie trafia do aplikacji jest przetwarzane ale otrzymuję błąd w przeglądarce "CORS". Cały czas myślałem że CORS są związane wyłącznie z stroną serwerową, dobrze myślałem?
Część serwerowa:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().disable();
http.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/users/register").permitAll()
.antMatchers(HttpMethod.POST, "/users/login").permitAll()
.anyRequest()
.permitAll()
.and()
.addFilter(getAuthenticationFilter())
.addFilter(new JwtFilter(authenticationManager(), userDetailsService))
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
public AuthenticationFilter getAuthenticationFilter() throws Exception {
final AuthenticationFilter filter = new AuthenticationFilter(authenticationManager(),bCryptPasswordEncoder);
filter.setFilterProcessesUrl("/users/login");
return filter;
}
Klient:
executeJWTAuthenticationService(credentailDto: CredentailDto) {
return this.http.post<any>(
this.url+ 'users/login',
JSON.stringify(credentailDto)
).pipe(
map(
data => {
return data;
}
)
);
}
Może ktoś podpowie gdzie popełniam błąd.