How do I use the access token in Loopback?

不羁的心 提交于 2019-12-11 12:04:22

问题


I am trying to use Loopback as a mobile backend.

I am also following this example: http://docs.strongloop.com/display/public/LB/Introducing+the+Coffee+Shop+Reviews+app

After I login on my iOS device, I receive an access token. All good. Now I want to call an endpoint that requires authentication. Just calling the endpoint gets me the message "AUTHENTICATION REQUIRED".

So I try to attach the access token to the request parameters as {"access_token":"1241341234513..."}. However, nothing happens.

What I'm confused by is that on the web application, there's no need to directly send the access token. How can I make this work on my mobile client?


回答1:


the lb-services service that is included with the demo injects the token into the authorization header of api requests automatically, you'll have to do the same with your mobile app.

if (LoopBackAuth.accessTokenId) {
    config.headers[authHeader] = LoopBackAuth.accessTokenId;
} else if (config.__isGetCurrentUser__) {...

https://github.com/strongloop/loopback-getting-started-intermediate/blob/master/client/js/services/lb-services.js#L4266




回答2:


You would need to make sure you send access_token in header of request every time or you can send access_token='value' as query string in url.



来源:https://stackoverflow.com/questions/30359463/how-do-i-use-the-access-token-in-loopback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!