make provider config simpler
All checks were successful
Build and Publish / build-release (push) Successful in 1m30s

This commit is contained in:
2026-05-04 16:06:19 -05:00
parent 44d89014fd
commit 2137cf4959
3 changed files with 9 additions and 31 deletions

View File

@@ -14,33 +14,20 @@ defmodule PolicyServiceWeb.Plugs.AuthenticationPlug do
## Options
- :provider - The OIDCC provider configuration worker name (required)
- :client_id - OAuth2 client ID (required) - can be a string or {module, function, args} tuple
- :client_secret - OAuth2 client secret (required) - can be a string or {module, function, args} tuple
- :required_scopes - List of required scopes (optional)
"""
def init(opts) do
provider = Keyword.fetch!(opts, :provider)
client_id = Keyword.fetch!(opts, :client_id)
client_secret = Keyword.fetch!(opts, :client_secret)
required_scopes = Keyword.get(opts, :required_scopes, [])
zitadel_config = Application.get_env(:policy_service, :zitadel, [])
%{
provider: provider,
client_id: resolve_config(client_id),
client_secret: resolve_config(client_secret),
required_scopes: required_scopes
client_id: Keyword.get(zitadel_config, :client_id),
client_secret: Keyword.get(zitadel_config, :client_secret),
required_scopes: Keyword.get(zitadel_config, :required_scopes, [])
}
end
defp resolve_config({module, function, args})
when is_atom(module) and is_atom(function) and is_list(args) do
apply(module, function, args)
end
defp resolve_config(value) when is_binary(value), do: value
defp resolve_config(value) when is_function(value, 0), do: value.()
defp resolve_config(value), do: value
@doc """
Authenticates the request by validating the JWT token.