我正在使用 auth2 身份验证和 reactjs 进行 spring boot 1.5+ 安全。用于使用 restful http 客户端的 http 调用。身份验证工作正常,我成功地从资源服务器访问数据。问题是注销代码不起作用,我在控制台上收到此错误:
POST http://localhost:8080/logout 403 ()
错误:“禁止”消息:“在请求参数‘_csrf’或标头‘X-XSRF-TOKEN’上发现无效的CSRF令牌‘null’。
我也在分享我的代码。
1) ReactJs 代码
handleLogout = (e) => {
client({
method: 'POST',
path: '/logout',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}}).then(response => {
console.log(response);
});
}
Run Code Online (Sandbox Code Playgroud)
2)宁静的http客户端
'use strict';
// client is custom code that configures rest.js to include support for HAL, URI Templates,
// and other things. It also sets the default Accept request header to application/hal+json.
// get the …Run Code Online (Sandbox Code Playgroud) 我正在做一个关于Spring Boot + oauth2 + websocket的例子。我在8098端口上运行的资源服务器上具有spring websocket配置和其他代码。我试图从运行在8080端口上的客户端应用程序连接它。但是,当我运行我的应用程序时,在浏览器控制台上收到错误401(未经授权)。我正在分享一些代码:
1)客户端应用程序(在8080端口上运行)的javaScript代码获取websocket连接
'use strict';
// pull in the SockJS JavaScript library for talking over WebSockets.
var SockJS = require('sockjs-client');
// pull in the stomp-websocket JavaScript library to use the STOMP sub-protocol.
require('stompjs');
function register(registrations) {
const access_token = localStorage.getItem("ACCESS_TOKEN");
console.log("Access Token " + access_token);
const csrf_token = localStorage.getItem("XSRF");
// Here is where the WebSocket is pointed at the server application’s /messages endpoint
// websocket use this URL to open TCP connection
var socket = …Run Code Online (Sandbox Code Playgroud) spring-security jwt reactjs spring-security-oauth2 spring-websocket