in postman when i entered my post request with Authorization and token value, then it works, however when i wanted to check it with axios it gives me 403 Http error (i've already provided authorization header in axios). (My token with Bearer is localStorage.getItem("CurrentUser")}) i am putting my axios below (when i checked token and request string, they both totally same with postman):
try {
await axios.post("http://localhost:8080/admins/post/" + allemployees[index].id,
{ headers: {'Authorization': localStorage.getItem("CurrentUser")} });
}
i also put my security.config, maybe problem was there:
@Configuration
@EnableWebSecurity
public class SecurityConfig{
private JwtAuthenticationEntryPoint handler;
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public AuthTokenFilter jwtAuthenticationFilter() {
return new AuthTokenFilter();
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.setAllowedOrigins(List.of("http://localhost:3000"));
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
@Bean
public SecurityFilterChain configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.cors()
.and()
.csrf().disable()
.exceptionHandling().authenticationEntryPoint(handler).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()
.antMatchers("/api/**")
.permitAll()
.anyRequest().authenticated()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout", "POST"))
.logoutSuccessUrl("http://localhost:3000/")
.invalidateHttpSession(true);
httpSecurity.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
return httpSecurity.build();
}
}
How can i solve this problem? Thank you.