diff --git a/lib/goth/token.ex b/lib/goth/token.ex index 5356ee5..5323a63 100644 --- a/lib/goth/token.ex +++ b/lib/goth/token.ex @@ -42,6 +42,8 @@ defmodule Goth.Token do * `:metadata` - for fetching token using Google internal metadata service + * `{:mfa, mfa}` - for building one of the above credentials at runtime + If `:source` is not set, Goth will: * Check application environment. You can set it with: `config :goth, json: File.read!("credentials.json")`. @@ -154,6 +156,10 @@ defmodule Goth.Token do * `:audience` - the audience you want an identity token for, default to `nil` If this parameter is provided, an identity token is returned instead of an access token + #### MFA tuple - `{:mfa, {mod, fun, args}}` + + For dynamically building a credential source at runtime. This function must return one of the above soruces. + ## Custom HTTP Client To use a custom HTTP client, define a function that receives a keyword list with fields @@ -296,6 +302,11 @@ defmodule Goth.Token do end end + defp request(%{source: {:mfa, {mod, fun, args}}} = config) do + source = apply(mod, fun, args) + request(%{config | source: source}) + end + defp request(%{source: {:service_account, credentials}} = config) do request(%{config | source: {:service_account, credentials, []}}) end