如何使用React前端和Spring Boot安全后端进行客户端身份验证检查?
我已经设置了spring boot安全依赖项如何使用React前端和Spring Boot安全后端进行客户端身份验证检查?,spring,reactjs,spring-mvc,spring-boot,spring-security,Spring,Reactjs,Spring Mvc,Spring Boot,Spring Security,我已经设置了spring boot安全依赖项 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> (我还完成了UsersDetailsService等的各种其他样板设置。) 在使用
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
(我还完成了UsersDetailsService等的各种其他样板设置。)
在使用html/thymeleaf的传统前端中,如果用户登录,我可以简单地执行类似的操作来显示注销链接
<form sec:authorize="isAuthenticated()" id="frmlogout" th:action="@{/logout}" method="post" class="form-inline">
<a href="javascript:{}" onclick="document.getElementById('frmlogout').submit(); return false;">Logout</a>
</form>
问题是,如何从react.js类执行类似的“isAuthenticated()”检查(以及角色检查)?有可能吗
理想的结果是,我可以将注销按钮添加到我的导航栏中,导航栏是在my.js类中定义的。这篇文章展示了一种使用会话cookie的方法,这是spring mvc中保护通信的传统方法
或者,您可以对API使用Basic Auth,并在React中实现登录逻辑。如果对API的调用导致HTTP 401未经验证,则要求用户提供凭据并使用in react来调用API。这篇文章介绍了一种使用会话cookie的方法,这是spring mvc中保护通信的传统方法
或者,您可以对API使用Basic Auth,并在React中实现登录逻辑。如果对API的调用导致HTTP 401未经验证,则要求用户提供凭据并使用in react调用API。检查此问题-检查此问题-
<form sec:authorize="isAuthenticated()" id="frmlogout" th:action="@{/logout}" method="post" class="form-inline">
<a href="javascript:{}" onclick="document.getElementById('frmlogout').submit(); return false;">Logout</a>
</form>