我使用的服务器是spring boot有spring安全性和客户端反应使用fetch发送请求获取数据有令牌不成功
响应:
邮递员成功:代码在客户端获取数据
let header = new Headers({
'X-Authorization': `Bearer ${token}`,
'Accept': 'application/json'
});
console.log(header)
return fetch(`http://localhost:8080/account/current`, {
method: 'GET',
headers: header
})
.then(checkHttpStatus)
.then(parseJSON)
.then(response => {
dispatch(receiveProtectedData(response.data));
})
.catch(error => {
if (error.response.status === 401) {
dispatch(loginUserFailure(error));
dispatch(push('/login'));
}
})
代码服务器:
http.csrf().disable().authorizeRequests()
.antMatchers(Constants.LOGIN_PATH, Constants.REFRESH_TOKEN_PATH).permitAll()
.antMatchers("/v2/api-docs", "/configuration/ui/**", "/swagger-resources/**", "/configuration/security/**", "/swagger-ui.html", "/webjars/**",
"/validatorUrl").permitAll()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.addFilterBefore(new CORSFilter(), ChannelProcessingFilter.class)
.addFilterBefore(buildLoginProcessingFilter(), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(buildJwtTokenAuthenticationProcessingFilter(), UsernamePasswordAuthenticationFilter.class);