How to Limit REST API to User-Specific Content

前端 未结 2 976
谎友^
谎友^ 2021-01-21 21:35

I have a fairly simple API setup on a MEAN stack using PassportJS. I have no problems setting up my routes with no security (grabbing general data) and with user authentication

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-21 21:58

    It seems that you are missing an api check on the userId

    for e.g. you have a route like /api/:userId/data/:dataId and you would like to ensure that only users who are allowed to access this data item can do so. Then what you would need to do is check that the userId provided in your authentication token is the same as the userId in the api route!

提交回复
热议问题