Albert
Albert

Reputation: 23

How do I use the access token in Loopback?

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?

Upvotes: 1

Views: 5872

Answers (2)

Abhishek Chopra
Abhishek Chopra

Reputation: 11

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.

Upvotes: 0

Kevin B
Kevin B

Reputation: 95022

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

Upvotes: 4

Related Questions