如何在环回中处理访问令牌



我是环回的新手,我想了解如何为所有API路径启用授权,以及访问令牌的用途。

我已经使用POST/Users/login-api注册了用户名和密码,并获得了响应中的访问令牌,相关屏幕截图https://i.stack.imgur.com/B0EFQ.png.我把这个记号设置如下https://i.stack.imgur.com/26ADI.png

我尝试了GET/Users api,但我得到了所需的授权错误

{"错误":{"name":"错误","状态":401,"message":"需要授权","statusCode":401,"code":"AUTHORIZATION_REQUIRED","堆栈":"错误:需要授权\n在C:\Users\prem\Desktop\test\testauth\node_modules\loopback\lib\application.js:39:21\n在C:\Users\prem\Desktop\t\testuth\node_modeles\loopback\lib\maodel.js:322:7\n在C:\Useres\prem\Destop\testauth\node_modules\loopack\common\models\acl.js:472:23\n在C:\Users \testoprem\testuth\node _modules\async\dist\async.js:36943\n:9 \n在C:\Users\prem\Desktop\test\testauth\node_modules\async\dist\async.js:356:16\n在迭代器回调处(C:\Users\prem\Deskt\test\ttestauth\node_modules\aync\dist\aync.js:936:13)\n在C:\Users\prem\Deskt\ test\testuth\node_modeles\async\dist\async.js:840:16\n n适用(C:\Users\prem\Desktop\test\testauth\node_modules\async\dist\async.js:21:25在_combinedTickCallback(internal/process/next_tick.js:67:7)\n在进程中_tickDomainCallback(internal/process/next_tick.js:122:9)"}}

但它适用于以204作为状态码的POST/Users/logout api。

请分享如何在授权标头中添加访问令牌的任何指导

简单的打字错误,您在请求中使用accesstoken作为参数,但关键字是access_token

正确请求:

http://localhost:3000/api/custs/logout?access_token=REPLACE-WITH-YOUR-ACCESS-TOKEN 

最新更新