如何在环回中使用访问令牌? [英] How do I use the access token in Loopback?

查看:110
本文介绍了如何在环回中使用访问令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Loopback用作移动后端.

I am trying to use Loopback as a mobile backend.

我也遵循以下示例: http ://docs.strongloop.com/display/public/LB/Introducing+the+Coffee+Shop+Reviews+app

在我的iOS设备上登录后,我会收到一个访问令牌.都好. 现在,我想调用一个需要身份验证的端点.只需呼叫端点,我就会收到消息需要身份验证".

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".

因此,我尝试将访问令牌作为{"access_token":"1241341234513 ..."}附加到请求参数.但是,什么也没发生.

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

我感到困惑的是,在Web应用程序上,不需要直接发送访问令牌.如何在我的移动客户端上进行这项工作?

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?

推荐答案

演示中随附的lb-services服务将令牌自动注入到api请求的授权标头中,您必须对自己执行的操作相同移动应用.

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

这篇关于如何在环回中使用访问令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆