如何发送请求获取api到spring服务器使用react redux有令牌

时间:2017-06-24 16:27:35

标签: java reactjs spring-boot spring-security redux

我使用的服务器是spring boot有spring安全性和客户端反应使用fetch发送请求获取数据有令牌不成功

错误: error here

请求: enter image description here

响应:

enter image description here

邮递员成功: enter image description here

代码在客户端获取数据

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);

0 个答案:

没有答案
相关问题