【发布时间】:2019-02-11 08:57:05
【问题描述】:
我正在编写一个 Web 应用程序,它允许用户使用 Google OAuth2 帐户登录。我在前端使用 Node React,在后端使用 Spring Boot。到目前为止,我的登录功能正常工作。注销功能似乎也有点工作,因为我能够在控制台日志中看到预期的响应。我遇到的麻烦是我希望在单击注销按钮后被重定向到http://localhost:8080/greeting,但这并没有发生。我究竟做错了什么?
Header.js
class Header extends Component {
renderContent(){
switch (this.props.auth){
case null:
return;
case false:
return <li><a href="login/google">Login</a></li>
default:
return <li><button onClick={this.handleLogout} >Logout</button></li>
}
}
...
handleLogout = () => {
axios({method: 'post',
url: "http://localhost:8080/logout",
withCredentials: true,
headers: {'X-XSRF-TOKEN': cookies.get('XSRF-TOKEN')}
})
.catch(error => console.log('BAD', error))
.then(reponse => console.log('GOOD', reponse));
return response;
}
}
WebApp.java
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**")
.authorizeRequests()
.antMatchers(
"/**",
"/login",
"/greeting",
"/error**",
"/api/**").permitAll()
.anyRequest().authenticated()
.and()
.exceptionHandling()
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/"))
.and()
.logout().logoutSuccessUrl("/greeting").permitAll()
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.and()
【问题讨论】:
标签: spring-boot react-redux axios spring-security-oauth2