Hi,
I've had a discussion with a Lightspeed support person regarding the way the API authentication is done, I allow myself to post it here as well, as the current authentication really sounds... broken to me.
From what we've heard, here is how it works in summary:
* An access token is valid for 10 minutes
* A refresh token has no validity expiration BUT once it's used to generate a new access token, it is revoked, and you will need to save the new refresh token returned when asking the new access token.
In your case, indeed, if you do not use it for a few days, your access token will become invalid, which means that you'll need to save somewhere the refresh token (which, indeed, make the security argument quite useless as in the case of a long-lived access token or a long-lived refresh token... you still need to save it somewhere in your database... except that it would be much easier to rotate an access token directly in the Lightspeed interface).
This makes this new model extremely hard to use for most apps (and especially apps that are used for a single customer, where the whole authorization process is therefore a bit useless: it would be much easier to simply have a way to directly create long-lived access tokens with reduced permissions, and be able to rotate them on demand).
But most importantly, it makes it extremely unreliable and not user-friendly at all (unless I've missed a complete point in the method).
Imagine the following scenario:
1) You're having an access token from the initial OAuth dance, along a refresh token. So far, everything's good. You can persist the refresh token in database to get a new token once it's expired.
2) The access token has expired => you can use the refresh token to get a new access token... BUT something bad happen. A lot of things can happen:
* You're using load balancing, and one instance is removed from your pool before you had the time to persist the token.
* Your database is temporarily down.
* A concurrent request has also used the same refresh token at the same time, making your second call invalid as the refresh token has expired.
* ...
THIS can happen, and so far the answer from Lightspeed to me has been "you'll need to do something to avoid those problems. Maybe design it so that the token requests are all handled in the same place." So basically the suggestion is to create a whole micro-service to do all this processing, just for generating an access token?
But what happen when one of those issues arise? Well... you're in a stuck state: your new access token will expire in 10 minutes, but you haven't been able to save the new refresh token... so after 10 minutes... well... you just need to ask the customer to re-authorize the app again to run the OAuth dance again, and get a new access/refresh token (not talking about the huge downtime if the customer is not here to do that re-authorization right away).
I honestly can't understand the security advantages that this solution brings, and I must be missing something quite important here. I've used a lot of API over the last few years, and this is the very first time I run through a such convoluted and unreliable system that basically runs under the assumption that "no server nor unexpected errors will occur".
Whenever I had to craete private integration on a given solution, I just had the possibility to create a long-lived token, with a given set of permissions, and a simple way to be able to rotate the key in case of securtiy. This allowed to directly feed the servers with an access token in an environment variables (which make it easier to secure it, and remove all the hassle of storing it in database).
Can someone from Lightspeed enlightens me on that, give some strong options on how to avoid the issues outlined before?...