Closed jgaehring closed 2 years ago
The 2.x version of the aggregator supports both 1.x and 2.x servers which created a few spots where we need to determine the server version... a simple way I found was to check the length of the access token! (example)
In 2.x the access tokens are JWTs which will always be much longer than the access tokens used in 1.x (believe they are 50 char long). But just thinking.... this method might only work when checking FK instances that are already authorized/connected to a farmOS server though.
Detecting the server version when first connecting FK to a server might be a bit more difficult.. an initial request to /api
will show the version for 2.x. Another complication is that the OAuth scopes used in 2.x will likely be different from 1.x. If the wrong scopes are used when connecting to either a 1.x or 2.x server, that authorization should fail. So perhaps some error catching will be necessary...
Detecting the server version when first connecting FK to a server might be a bit more difficult.. an initial request to
/api
will show the version for 2.x. Another complication is that the OAuth scopes used in 2.x will likely be different from 1.x. If the wrong scopes are used when connecting to either a 1.x or 2.x server, that authorization should fail. So perhaps some error catching will be necessary...
This sounds right. I was starting to write this in reply to https://farmos.discourse.group/t/migrating-from-farmos-app-to-v1-farmos-app but then I found this issue;
farmos.app
send a request to /api
or /api/schema
. If it gets a valid non-404
response, then it's a 2.x server, otherwise assume it's a 1.x server - until proven otherwise.v1.farmos.app
send a request to /farm.json
. If it gets a valid (empty array when not logged in) response continue with rendering the 1.x version of farmos.app
otherwise display a help page about enabling the additional CORS domain.otherwise assume it's a 1.x server - until proven otherwise.
Yea, I think this is the key to any approach. I will probably concentrate most of my efforts on the initial authorization process, on the assumption that it shouldn't be possible for users with fresh installs to get past that step anyways, so I shouldn't need to guard against those kinds of requests.
Of course, where this may get really thorny is for users whose server just recently underwent a migration to 2.x, and then try to connect via v1.farmos.app. That will probably be point with the greatest likelihood of data loss, too.
Since we'll have two versions of both Field Kit and farmOS living side by side for a while as folks migrate, we need to ensure that FK can detect which version of the farmOS server it's connecting to, and if it doesn't match, provide intelligible error message explaining why it's incompatible, and a link to the other version of FK. We should do so before any viable version of FK 2.x is out in the wild, so preferably before the beta release.