【问题标题】:Authenticate DDP Client using Node.js使用 Node.js 验证 DDP 客户端
【发布时间】:2014-09-13 09:27:37
【问题描述】:

node.js DDP 客户端(使用node-ddp)调用 DDP 服务器上的方法 insertMessage,将文档保存到 mongodb。

Meteor.methods({
    'insertMessage': function(msg) {
        Messages.insert({'msg':msg, 'userId': userId})
    }
})

如何只允许经过身份验证的 DDP 客户端插入包含其唯一标识符 userId 的文档,而不能伪造其他人的 userId?我查看了ddp-login,但似乎成功的身份验证提供了一个令牌,这个令牌可以用于我们的目的吗?

Meteor.methods({
    'insertMessage': function(msg) {

        // Check that the current user's userId (how can we do this?)
        userId = getUserId()

        Messages.insert({'msg':msg, 'userId': userId})
    }
})

【问题讨论】:

  • 在方法中,this.userId 将是登录用户的用户 ID,如果用户未登录,则为 null

标签: javascript node.js meteor ddp


【解决方案1】:

在服务器中,你有这个参数..

Meteor.methods

this.userId

this.setUserId

this.isSimulation

this.unblock

this.connection

Meteor.methods({
    'insertMessage': function(msg) {
        userId = this.userId;
        Messages.insert({'msg':msg, 'userId': userId})
    }
})

【讨论】:

    猜你喜欢
    • 2016-08-29
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多