Goth.start_link
start_link
, go back to Goth module for more information.
Starts the server.
When the server is started, we attempt to fetch the token and store it in internal cache. If we fail, we'll try up to 3 times with 1000ms cooldown between requests and if we couldn't retrieve it, we crash.
Options
:name
- the name to register the server under.:source
- the source to retrieve the token from.See documentation for the
:source
option inGoth.Token.fetch/1
for more information.:retry_after
- Time in milliseconds between retrying requests, defaults to1000
.:refresh_before
- Time in seconds before the token is about to expire that it is tried to be automatically refreshed. Defaults to300
(5 minutes).:http_client
- a{module, opts}
tuple, wheremodule
implements theGoth.HTTPClient
behaviour andopts
is a keywords list to initialize the client with. Defaults to{Goth.HTTPClient.Hackney, []}
.
Examples
Generate a token using a service account credentials file:
iex> credentials = "credentials.json" |> File.read!() |> Jason.decode!()
iex> Goth.start_link(name: MyApp.Goth, source: {:service_account, credentials, []})
iex> Goth.fetch(MyApp.Goth)
{:ok, %Goth.Token{...}}
Retrieve the token using a refresh token:
iex> credentials = "credentials.json" |> File.read!() |> Jason.decode!()
iex> Goth.start_link(name: MyApp.Goth, source: {:refresh_token, credentials, []})
iex> Goth.fetch(MyApp.Goth)
{:ok, %Goth.Token{...}}
Retrieve the token using the Google metadata server:
iex> Goth.start_link(name: MyApp.Goth, source: {:metadata, []})
iex> Goth.fetch(MyApp.Goth)
{:ok, %Goth.Token{...}}