0

我正在尝试使用 Meteor 用户 hashedToken 访问 Restivus API

这是我的代码:

Transfer= new Mongo.Collection("transfer");

  var Api = new Restivus({
   useDefaultAuth: true,
    auth: {
      token: 'auth.apiKey',
      user: function () {
        return {
          userId: this.request.headers['user-id'],
          token: this.request.headers['login-token']
        };
      }
    },
    prettyJson: true
  });
      Api.addRoute('transfer', {authRequired: true}, {
        post: function () {
        var user = Meteor.users.findOne({_id:this.urlParams.id});
        var userName = user.profile.name;
            return {
            userId: this.urlParams.id,
            userName:userName
            }
        }
      });

我试图用以下方式调用它:

curl -H "user-id: LGmaefwFZShu33GPA" -H "login-token: fG4HfWmPSp4Yd2HqUhNJEmAKcz4348Ng4WyyDaTHmLs=" http://localhost:3000/api/transfer

我收到了这个回复

{
"status": "error"
"message": "Unauthorized"
}
4

1 回答 1

0

以下应该有效:

var Api = new Restivus({
   useDefaultAuth: true,
   prettyJson: true
 });

auth如果保持useDefaultAuth为,则无需输入选项true

于 2016-08-30T15:38:18.737 回答