【发布时间】:2019-04-18 22:27:27
【问题描述】:
我正在尝试使用 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?
【问题讨论】:
标签: cookies socket.io jwt feathersjs