i8beef / HomeAutio.Mqtt.GoogleHome

MIT License
215 stars 29 forks source link

feature proposal: alternative token store mechanisms #49

Closed redging-very-well closed 5 years ago

redging-very-well commented 5 years ago

I'm using this excellent project in Heroku and I'm facing an issue with the way that the token store is implemented.

Essentially, Heroku (and probably other PaaS providers) cycles the app periodically and as such the ephemeral storage of the container is lost. Because mountable volumes aren't supported and the built in PersistedGrantStore is backed by the file system, any record of issued refresh tokens is also lost, and so google actions fails to refresh its token.

I propose an optional data store for the tokens. The current oauth.tokenStoreFile key could be deprecated and superseded by a new oauth.tokenStore key as follows:

    "oauth": {
        "tokenStore": {
          "type": "file",
          "tokenStoreFile": "config/tokens.json"
        }
        ...

For something like mongoDB as a token store:

    "oauth": {
        "tokenStore": {
          "type": "mongo",
          "connectionString": "mongodb://localhost:27017"
        }
        ...

I intend to fork this repo and implement this for my own use. If desired, I can raise a PR to pull this functionality back in.

i8beef commented 5 years ago

While certainly possible, I think that's a bit outside of the scope here... Obviously a file based storage was chosen here because of its ubiquitous nature and lack of external dependencies. I'm not sure how you could realistically run at all without volumes, given that the config files, device files, certificates for signing, etc. all need somewhere to live too.

redging-very-well commented 5 years ago

Okay fair enough!

For context, the way I'm running this in Heroku is I essentially have a Dockerfile that is based on your image, and I bundle into it the config, devices, and certs so they are all part of the image. That's all read-only anyway and so survives restarts.

My reason for running this in Heroku is primarily because I didn't want to open up my local network to the internet. With Heroku, I can run this, MQTT, Mongo, and potentially a bunch of other addons and services for free. On my local network, I have some other services that connect to the Heroku cloud MQTT service and so that serves as an integration point.

In any case, I've created the mongo store and set up the code to be able to select between a file-based store or a mongo store (or anything else that anyone might like to implement).

Thanks again for all of your hard work on this - it meant I didn't need to spend hours writing all of those action APIs myself :)