peburrows / goth

Elixir package for Oauth authentication via Google Cloud APIs
http://hexdocs.pm/goth
MIT License
289 stars 111 forks source link

Add a way to clear or bypass the TokenStore #65

Closed potibas closed 3 years ago

potibas commented 5 years ago

It would help a lot with testing if we could have a setting to ignore the TokenStore, forcing it to always get a new one.

Or, if there was a TokenStore.clear method we could at least create a test helper to clear the cache before specific tests, making them predictable.

I'm using bypass to simulate several conditions (token created, error creating token etc) and there comes a point where the token I created for a given scope is already cached from previous tests, affecting their predictability.

potibas commented 5 years ago

I took an attempt for a TokenStore.clear method, and it's working for my current purposes.

However, I'm sure there's more to it. It seems I should also delete the timers that refresh the tokens in the store when removing them, but I'm not sure how to go about it.

I don't think is good enough for a pull request (also not even sure if a pull request is wanted in this case). In case anyone is interested: gok-dev/goth@515e664bd078c9ced3fcbaf6b0289070d7024dcd

peburrows commented 5 years ago

Yeah, what you've done looks like a good start, but I think you're right about the refresh timers. To properly do that, we'll need to start storing those returned timer refs as part of the state so that we can call :timer.cancel/1 when we clear out the tokens.

wojtekmach commented 3 years ago

In #83 we're introducing a new API where you could start different Goth instances for different scenarios. You can also use the new Goth.Token.fetch/1 to bypass the cache altogether and hit the external service directly.