我正在尝试使用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?
发布于 2018-11-15 21:08:04
client.authenticate(userData)将使用SocketIO进行身份验证(因为您已经在使用client.configure(socketio(socket));),并将其存储在您传递的存储中(在您的示例中是cookieStorage )。
https://stackoverflow.com/questions/53325890
复制相似问题