我是loopback的新手,我想了解如何为所有API路径启用授权以及访问令牌的使用方法。
我已使用POST / Users / login api登录了注册用户名,密码并获得了响应中的访问令牌,相关屏幕截图 https://i.stack.imgur.com/B0EFQ.png。 我将该令牌设置如下 https://i.stack.imgur.com/26ADI.png
我尝试了GET / Users api,但我得到了授权所需的错误
{ "错误":{ " name":"错误", " status":401, "消息":"需要授权", " statusCode":401, "代码":" AUTHORIZATION_REQUIRED", " stack":"错误:需要授权\ n在C:\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ loopback \ lib \ application.js:399:21 \ n at C :\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ loopback \ lib \ model.js:322:7 \ n在C:\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ loopback \ common \ models \ acl .js:472:23 \ n在C:\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ async \ dist \ async.js:3694:9 \ n在C:\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ async \ dist \ async.js:356:16 \ n at iteratorCallback(C:\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ async \ dist \ async.js:936:13)\ n at C :\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ async \ dist \ async.js:840:16 \ n在C:\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ async \ dist \ async.js :3691:13 \ n在应用(C:\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ async \ dist \ async.js:21:25)\ n在C:\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ async \ dist \ async.js:56:12 \ n在C:\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ loopba ck \ common \ models \ acl.js:454:17 \ n在C:\ Users \ prem \ Desktop \ test \ testauth \ node_modules \ loopback \ common \ models \ role.js:273:21 \ n在_combinedTickCallback(内部/process/next_tick.js:67:7)\n at process._tickDomainCallback(internal / process / next_tick.js:122:9)" } }
但它用于POST / Users / logout api,其中204为状态代码。
请分享有关如何在授权标头中添加访问令牌的任何指导
答案 0 :(得分:0)
简单的拼写错误,您在请求中使用accesstoken
作为参数,但关键字为access_token
更正请求:
http://localhost:3000/api/custs/logout?access_token=REPLACE-WITH-YOUR-ACCESS-TOKEN