首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >feathers.js ->身份验证令牌丢失

feathers.js ->身份验证令牌丢失
EN

Stack Overflow用户
提问于 2017-04-02 08:07:47
回答 1查看 648关注 0票数 0

我有一个feathters.js应用程序,现在我想保护创建和更新钩子。我使用一个socket.io客户端,目前正在使用JWT。我已经添加了我认为需要添加的内容,但是我得到了Error: Authentication token missingError Authenticating。稍后我从我的代码中了解到这一点。我有后端/前端的情况

到目前为止,这就是我所实现的。

文件: backend\backend.js (应用程序的配置在backend\index.js中调用)

代码语言:javascript
复制
'use strict';

const path = require('path');
const serveStatic = require('feathers').static;
const favicon = require('serve-favicon');
const compress = require('compression');
const cors = require('cors');
const feathers = require('feathers');
const configuration = require('feathers-configuration');
const authentication = require('feathers-authentication');
const hooks = require('feathers-hooks');
const rest = require('feathers-rest');
const bodyParser = require('body-parser');
const socketio = require('feathers-socketio');
const middleware = require('./middleware/index');
const services = require('./services/index');

const appFeathers = feathers();

appFeathers.configure(configuration(path.join(__dirname, '..')));

appFeathers.use(compress())
    .options('*', cors())
    .use(cors())
    .use(favicon(path.join(appFeathers.get('public'), 'favicon.ico')))
    .use('/', serveStatic(appFeathers.get('public')))
    .use(bodyParser.json())
    .use(bodyParser.urlencoded({extended: true}))
    .configure(hooks())
    .configure(rest())
    .configure(socketio())
    .configure(services)
    .configure(middleware)
    .configure(authentication());

module.exports = appFeathers;

文件: backend\config\default.json

代码语言:javascript
复制
{
    "host": "localhost",
    "port": 3001,
    "mysql_connection": "mysql://CONNECTION_STRING",
    "public": "../public/",
    "auth": {
        "idField": "id",
        "token": {
            "secret": "SECRET_KEY"
        },
        "local": {}
    }
}

在前端的一个工作部分:

代码语言:javascript
复制
<template>
    <div class="vttIndex">
        idnex.vue
        todo: eagle.js slideshow
        todo: first info
        <ul>
            <li v-for="message in listMessages">
                {{ message }}
            </li>
        </ul>
    </div>
</template>

<script>
    import feathers from 'feathers/client';
    import socketio from 'feathers-socketio/client';
    import hooks from 'feathers-hooks';
    import io from 'socket.io-client';
    import authentication from 'feathers-authentication/client';
    import * as process from "../nuxt.config";

    const vttSocket = io(process.env.backendUrl);
    const vttFeathers = feathers()
        .configure(socketio(vttSocket))
        .configure(hooks())
        .configure(authentication());

    const serviceMessage = vttFeathers.service('messages');


vttFeathers.authenticate({
    type: 'token',
    'token ': 'SECRET_KEY'
}).then(function(result){
    console.log('Authenticated!', result);
}).catch(function(error){
    console.error('Error authenticating!', error);
});

    export default {
        layout: 'default',
        data: function() {
            return {
                listMessages: []
            }
        },
        mounted: function() {
            serviceMessage.find().then(page => {
                this.listMessages = page.data;
            });
            serviceMessage.on('created', (serviceMessage) => {
                this.listMessages.push(serviceMessage);
            });
        }
    }
</script>

作为标记,我有后端json文件的秘密密钥。正如您所看到的,现在我只尝试记录控制台消息。它在做些什么,因为我的错误信息来自那里。

问题

我在哪里错过了这个功能呢?

目标

以备不时之需。我的目标是选择所有的“公共”数据,并在我的客户端选择一个令牌,然后使用管理部分(可能是0auth )。因此,一般的“SELECT”内容是通过令牌来保护的,而不是完全没有身份验证。

溶液

好吧,我解决了,算是吧。我首先需要创建一个用户。然后,我需要对用户进行本地登录。返回一个令牌。如果我用它,那就没有问题了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-02 11:20:01

要使用令牌,您必须首先确保它是生成的。我用密匙作为标记什么是不对的。当您第一次使用“本地”类型(默认电子邮件和密码)时,它将创建一个令牌,然后您可以使用该方法“令牌”。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43166071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档