Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Smart Home: Cache authorization tokens #423

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bramkragten
Copy link

@bramkragten bramkragten commented Apr 13, 2021

Closes #421

For every requestSync or reportState request, a new JWTClient is created, causing a post request to get a new token:

const jwtClient = new google.auth.JWT(

The token that is returned is valid for an hour, but the client and token are still recreated for every request.

With this PR, the JWTClient is created just once, on first use, this causes that the token is cached and only refreshed when it is no longer valid.

Furthermore, during the request of a new token, all other requests now wait for this token to finish loading instead of starting a new load.

This will drastically improve the performance and lower the number of requests to the Google Authentication API.

(Sorry, prettier doesn't seem agree with your style guidelines)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Smart Home: Cache authorization tokens
1 participant