Sails disable criteria for REST in GET

2019-08-08 14:14发布

I have implemented passport-local strategy and passport-bearer strategy.

When user logins with username/password credentials, I generate JSON Web Token which returns to requester. On each request I get access_token from query, decode this token from JWT to object and make bearer authorization implemented in /api/policies. And all auth works fine.

But when I provide this access_token to RESTful route i.e. user I got empty array.

The problem, that Sails accepts access_token as criteria.

Example:

GET /user ## Forbidden GET /user?access_token=<token> ## Empty array

How can I disable or fix it?

标签: rest sails.js
1条回答
劫难
2楼-- · 2019-08-08 15:11

You would probably be better off sending your access token in a header than in the URL. But if what your asking is how to blacklist a certain property from being used as criteria in a blueprint route, it can be done in the following way in your config/routes.js file:

"GET /user": {blueprint: "find", criteria: {blacklist: ["access_token"]}}

This will override the default blacklist, so you may want to include those defaults in your custom array:

"GET /user": {
  blueprint: "find", 
  criteria: {
      blacklist: ["access_token", "limit", "skip", "sort", "populate"]
  }
}
查看更多
登录 后发表回答