Skip to content

Commit

Permalink
Add the option to get the client secret dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrodevs committed Sep 19, 2023
1 parent a430ec7 commit 14d3682
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/ueberauth/strategy/google/oauth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ defmodule Ueberauth.Strategy.Google.OAuth do
"""
def client(opts \\ []) do
config = Application.get_env(:ueberauth, __MODULE__, [])
opts = @defaults |> Keyword.merge(config) |> Keyword.merge(opts) |> resolve_values()

opts =
@defaults
|> Keyword.merge(config)
|> Keyword.merge(opts)
|> resolve_values()
|> generate_secret()

json_library = Ueberauth.json_library()

OAuth2.Client.new(opts)
Expand Down Expand Up @@ -89,4 +96,14 @@ defmodule Ueberauth.Strategy.Google.OAuth do

defp resolve_value({m, f, a}) when is_atom(m) and is_atom(f), do: apply(m, f, a)
defp resolve_value(v), do: v

defp generate_secret(opts) do
if is_tuple(opts[:client_secret]) do
{module, fun} = opts[:client_secret]
secret = apply(module, fun, [opts])
Keyword.put(opts, :client_secret, secret)
else
opts
end
end
end

0 comments on commit 14d3682

Please sign in to comment.