【问题标题】:Is it possible to pass your current user id to remote DDP server's `this.userId`?是否可以将您当前的用户 ID 传递给远程 DDP 服务器的 `this.userId`?
【发布时间】:2014-06-07 15:08:50
【问题描述】:

我有两个使用相同数据库的流星应用程序,一个是移动应用程序(主要),另一个是桌面应用程序。

我想从桌面应用调用远程移动方法来创建列表,这样我就不必重复代码'Listing.create'

我假设我在桌面应用程序上登录的Meteor.userId 会在调用远程移动方法时被转移,但事实并非如此,因为它是未定义的。

我也有 Oauth 和电子邮件身份验证,但似乎没有一种简单的方法可以使用 OAuth 登录(通过调用“登录”登录非常适合密码)。

调用远程方法的最佳方法是什么,因为它没有登录就失败了?我想我可以将 userId 作为字符串传递,但这会打开该方法以进行黑客攻击

Mobile server, m.foo.com, MONGO_URL bar.com

Meteor.methods({

  'Listing.create': function(){

    if (!this.userId) throw new Meteor.Error(503, 'No user account');

    ...

    db.listings.insert(...);
  }

})

// on client
Meteor.userId() // 1234


Desktop server, foo.com, MONGO_URL bar.com

MobileDDP = DDP.connect('http://m.foo.com')

MobileDDP.call('Listing.create', function(err, res) {
  console.log(err, res)
});

【问题讨论】:

    标签: meteor ddp


    【解决方案1】:

    是的。该方法与此答案相同:Authenticating with Meteor via DDP (and SRP?)

    唯一的区别是使用Meteor.call("login".. 代替ddp-tools,而不是使用Meteor.call("login"..,将参数与登录类型相匹配。

    如果登录是 Facebook 或其他 OAuth 登录,则必须使用 loginToken 而不是普通的用户名和密码。

    【讨论】:

    • 谢谢!我会在星期一试试这个。从一些额外的谷歌搜索来看,一旦我登录桌面应用程序,我就可以使用 var token = Accounts._storedLoginToken() 并将其传递给 Meteor.call("login", {resume: token}, .. 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    相关资源
    最近更新 更多