Aleks
Aleks

Reputation: 5864

How to configure loopback to use access_token in the header

I'm using access_token handling logic form loopback. It works fine, but unfortunately expects the access_token in the URL.

Can I configure loopback to use the access_token in the header custom field instead?

Upvotes: 7

Views: 3470

Answers (2)

Varun Kumar
Varun Kumar

Reputation: 2751

Docs- https://loopback.io/doc/en/lb3/Making-authenticated-requests.html

Pass the following header in request config (use your token)-

headers: {
    Authorization: '1vKbyJc9D2pJaE5sZWDqKxcJYlOfPab4eO8giuRMkfOxvoHKGUBRDcNvP4JwDIxe'
}

No configuration needed in server.

Upvotes: 0

RootHacker
RootHacker

Reputation: 1107

Initialize Loopback Token Middleware check the docs

A sample code for enabling loopback.token middleware

app.use(loopback.token({  
  cookies: ['access_token'],
  headers: ['access_token', 'X-Access-Token'],
  params:  ['access_token']
  //additional keys (check docs for more info)
}));

It checks for these values in cookies, headers, and query string parameters

Upvotes: 9

Related Questions