From 14d368296c64e7946694d31052d589a0104fe599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Guti=C3=A9rrez?= Date: Tue, 19 Sep 2023 13:47:41 -0600 Subject: [PATCH] Add the option to get the client secret dynamically --- lib/ueberauth/strategy/google/oauth.ex | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/ueberauth/strategy/google/oauth.ex b/lib/ueberauth/strategy/google/oauth.ex index c818cca..e85d9c8 100644 --- a/lib/ueberauth/strategy/google/oauth.ex +++ b/lib/ueberauth/strategy/google/oauth.ex @@ -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) @@ -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