goth v0.3.2 Goth.TokenStore

The Goth.TokenStore is a simple GenServer that manages storage and retrieval of tokens Goth.Token. When adding to the token store, it also queues tokens for a refresh before they expire: ten seconds before the token is set to expire, the TokenStore will call the API to get a new token and replace the expired token in the store.

Summary

Functions

Retrieve a token from the TokenStore

Store a token in the TokenStore. Upon storage, Goth will queue the token to be refreshed ten seconds before its expiration

Functions

find(scope)

Specs

find(String.t) :: {:ok, Goth.Token.t} | :error

Retrieve a token from the TokenStore.

token = %Goth.Token{type:    "Bearer",
                    token:   "123",
                    scope:   "scope",
                    expires: :os.system_time(:seconds) + 3600}
Goth.TokenStore.store(token)
{:ok, ^token} = Goth.TokenStore.find(token.scope)
start_link()
store(token)

Specs

store(Goth.Token.t) :: pid

Store a token in the TokenStore. Upon storage, Goth will queue the token to be refreshed ten seconds before its expiration.

store(scopes, token)