FeathersJS socketio jwt 认证
FeathersJS socketio jwt authentication
我正在尝试使用 feathersjs
向我的应用程序添加身份验证。我无法理解为什么我的 jwt
令牌没有被发送,即使我从服务器收到 jwt
。
这是我的 angular
代码:
import {CookieStorage} from 'cookie-storage';
import {JwtHelperService} from '@auth0/angular-jwt';
import feathers from '@feathersjs/feathers';
import socketio from '@feathersjs/socketio-client';
import auth from '@feathersjs/authentication-client';
import {tap} from 'rxjs/operators';
import * as io from 'socket.io-client';
const socket = io('http://localhost:3030');
const cookieStorage = new CookieStorage();
const client = feathers();
client.configure(socketio(socket));
client.configure(auth({ storage: cookieStorage }));
socket.emit('authenticate', userData, function(message, data) {
console.log(message); // message will be null
console.log(data); // data will be {"accessToken": "your token"}
// You can now send authenticated messages to the server
});
此代码有效,我将 jwt
accessToken
返回给浏览器,但 cookieStorage
部分未保存 cookie。如果我使用以下代码切换 socket.emit('authenticate')
部分,它会起作用:
client.authenticate(userData)
但是,我想使用 socketio
进行身份验证并将 jwt
保存在 cookie 中,而不是使用以下方法:
如何获取 socketio
身份验证事件以在 cookie 中设置 jwt
?
client.authenticate(userData)
将使用SocketIO进行身份验证(因为您已经在使用client.configure(socketio(socket));
)并将其存储在您传递的存储中(即cookieStorage
在你的情况下)。
我正在尝试使用 feathersjs
向我的应用程序添加身份验证。我无法理解为什么我的 jwt
令牌没有被发送,即使我从服务器收到 jwt
。
这是我的 angular
代码:
import {CookieStorage} from 'cookie-storage';
import {JwtHelperService} from '@auth0/angular-jwt';
import feathers from '@feathersjs/feathers';
import socketio from '@feathersjs/socketio-client';
import auth from '@feathersjs/authentication-client';
import {tap} from 'rxjs/operators';
import * as io from 'socket.io-client';
const socket = io('http://localhost:3030');
const cookieStorage = new CookieStorage();
const client = feathers();
client.configure(socketio(socket));
client.configure(auth({ storage: cookieStorage }));
socket.emit('authenticate', userData, function(message, data) {
console.log(message); // message will be null
console.log(data); // data will be {"accessToken": "your token"}
// You can now send authenticated messages to the server
});
此代码有效,我将 jwt
accessToken
返回给浏览器,但 cookieStorage
部分未保存 cookie。如果我使用以下代码切换 socket.emit('authenticate')
部分,它会起作用:
client.authenticate(userData)
但是,我想使用 socketio
进行身份验证并将 jwt
保存在 cookie 中,而不是使用以下方法:
如何获取 socketio
身份验证事件以在 cookie 中设置 jwt
?
client.authenticate(userData)
将使用SocketIO进行身份验证(因为您已经在使用client.configure(socketio(socket));
)并将其存储在您传递的存储中(即cookieStorage
在你的情况下)。