zoho / zohocrm-php-sdk-6.0

Apache License 2.0
1 stars 1 forks source link

Auth Tokens in a multi-server production environment #4

Closed cannycookie closed 4 months ago

cannycookie commented 4 months ago

We have a Laravel application that connects to Zoho perfectly using this SDK but in production we have more than one server and I need the auth token to be stored on a remote S3 disk.

I initially didn't think this would be a problem as we pass the local copy location of the file to the SDK. But, I've realised that the SDK updates the token with a new expiry timestamp after each use which means that the different servers will end up with different versions of the token.

My first thought was to create overrides for the FileStore and InitializeBuilder class (which references the FileStore) so we can pass a storage disk to the function allowing the file to be referenced on S3 instead.

https://github.com/zoho/zohocrm-php-sdk-6.0/blob/master/src/com/zoho/crm/api/InitializeBuilder.php
https://github.com/zoho/zohocrm-php-sdk-6.0/blob/master/src/com/zoho/api/authenticator/store/FileStore.php

My only concern with this approach is the risk of future updates to these classes and having to rework the changes. If it's infrequently then maybe not a issue.

Perhaps a better idea could be to setup a file watcher and whenever we see a change to the local token file, put it to the S3 bucket. Seems like could be a sensible plan as it means we don't need to change the SDK code but each time a request is made we will need to first get the file from s3 (as another server might have changed it since we last used it). That change would then be observed by the file watcher and resend it back to S3. Risk of creating a circular reference here but maybe solvable by setting a flag on the file when we put it manually to tell the file watcher to ignore this change.

Just wondering if anyone else has faced or dealt with this issue.

All suggestions welcome.

Many Thanks Lee

raja-7453 commented 4 months ago

@cannycookie Please get in touch with support@zohocrm.com, for further updates. We will follow up on this request, over there.

Thanks!