Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying an mfa tuple for a credentials source #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/goth/token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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")`.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down