loopback api - persist AccessToken

0

First and foremost, my setup:

  • Ubuntu Server 18.04
  • Loopback API 3.X
  • Node version 12.6

My issue:

I set up Loopback API and created a few models and users. Now, all I need LoopbackAPI for is really to POST customer-created Plans via Chargebee WebHook.

Here is a short explanation on how it is supposed to work:

  1. Customer creates a plan
  2. Chargebee WebHook authenticates via AccessToken at LoopbackAPI (e.g. http://api-url/example?request_token=12345678
  3. The details of the created plan are then sent via POST to LoopbackAPI

This works as long as the server is running and I manually login (curl) with the user and create the AccessToken. If that created token is used the whole chain works fine. However, as soon as I restart the server I am unable to login because the AccessToken is not valid anymore (401 on chargebee).

The AccessToken-Datasource is set to be stored in mysql and I think this is the issue here. The table is there and when I manually login I see one row with the created user+token but as soon as the server restarts its gone (empty table)

I am mainly Ops and not really a Developer, therefore please let me know if I making a big mistake here or if I forgot to provide needed info. My main question is how to get this one AccessToken to persist after reboot but if someone got any security recommendations I would love to hear them as well.

Cheers

Steven

Posted 2019-07-17T07:15:22.143

Reputation: 688

Answers

0

I figured out what was wrong. In any case someone got the same issue this might help. In my case the Database was at fault. For some reason (I did not investigate) loopback was unable to write the AccessToken into the AccessToken-Table despite all the other tables working (Users, ACL...) I changed the AccessToken back to use "DB" as storage, with DB being a local file where loopback will store the AccessToken. This works consistent and also after rebooting the server.

Steven

Posted 2019-07-17T07:15:22.143

Reputation: 688