javascript - 带铁路由器的 meteor 休息 api

标签 javascript meteor

我有一个 rest api 在我的 meteor 应用程序上运行,带有 reststop2。该项目现已折旧说明:

Everything that this package is capable of can now be accomplished using iron-router server-side routes and core Meteor packages (for example accounts-password).

rest-api 的帮助下我已经启动并运行了端点,但我在身份验证方面遇到了困难。上面的语句建议使用 accounts-password 但我看不到任何可以在服务器上使用的方法,它们都是针对客户端的。

我也尝试过使用:

Accounts._checkPassword(user, password);

但我收到错误 TypeError: undefined is not a function

最佳答案

Iron-router 内置了中间件选项,您可以在其中为您的 REST API 进行身份验证:https://github.com/EventedMind/iron-router/blob/devel/examples/middleware/middleware.js

在此函数中,您可以验证您的用户并在它不是有效凭据时抛出错误。

我不知道这是否有帮助,但我正在使用 Google 访问 token 对我的用户进行身份验证。这是我的代码(在 coffeescript 中):

getUserByToken: (token) ->
    getUserByEmail getEmailByToken token

getEmailByToken: (token) ->
    getUserInfo(token)?.email

getUserInfo: (token) ->
    try
        oauthUser = HTTP.get 'https://www.googleapis.com/oauth2/v1/userinfo?access_token=' + token
    catch error
        console.log 'error authenticating', error
        null
    oauthUser?.data

getUserByEmail: (email) ->
    if email
        Meteor.users.findOne 'services.google.email': email

关于javascript - 带铁路由器的 meteor 休息 api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26231442/

相关文章:

javascript - 试图将 "zone.js"编译为外部模块,但它看起来像一个全局模块

javascript - node.js res.write 不起作用

javascript - 是否可以对 Meteor 用户进行响应式(Reactive) isVerified 调用?

javascript - meteor 检测集合中字段的存在

javascript - Meteor.call 'load' 参数

javascript - 动态添加和删除 div 行到字段集,JQuery

javascript - 使用 data-clear-btn ="true"克隆 jquery 移动输入字段

javascript - 如何通过 jquery 提交表单并检索 JSON 数据?

mongodb - 如何管理在 AWS AMAZON EC2 上运行的 Meteor 应用程序

ios - 使用 swiftDDP 将对象传递给 Meteor 方法