diff --git a/lib/ex_oauth2_provider/config.ex b/lib/ex_oauth2_provider/config.ex index 4368fac5..d4937a95 100644 --- a/lib/ex_oauth2_provider/config.ex +++ b/lib/ex_oauth2_provider/config.ex @@ -43,12 +43,18 @@ defmodule ExOauth2Provider.Config do do: get_oauth_struct(config, :application) defp get_oauth_struct(config, name, namespace \\ "oauth") do - context = Macro.camelize("#{namespace}_#{name}s") - module = Macro.camelize("#{namespace}_#{name}") + case get(config, name) do + nil -> + context = Macro.camelize("#{namespace}_#{name}s") + module = Macro.camelize("#{namespace}_#{name}") - config - |> get(name) - |> Kernel.||(app_module(config, context, module)) + config + |> get(name) + |> Kernel.||(app_module(config, context, module)) + + module -> + module + end end @doc """ diff --git a/test/ex_oauth2_provider/config_test.exs b/test/ex_oauth2_provider/config_test.exs index 06d5dd03..bf08659b 100644 --- a/test/ex_oauth2_provider/config_test.exs +++ b/test/ex_oauth2_provider/config_test.exs @@ -10,6 +10,33 @@ defmodule ExOauth2Provider.ConfigTest do end) end + test "application/1" do + assert Config.application(otp_app: :my_app) == MyApp.OauthApplications.OauthApplication + + Application.delete_env(:ex_oauth2_provider, ExOauth2Provider) + Application.put_env(:my_app, ExOauth2Provider, application: :custom_value) + + assert Config.application(otp_app: :my_app) == :custom_value + end + + test "acess_token/1" do + assert Config.access_token(otp_app: :my_app) == MyApp.OauthAccessTokens.OauthAccessToken + + Application.delete_env(:ex_oauth2_provider, ExOauth2Provider) + Application.put_env(:my_app, ExOauth2Provider, access_token: :custom_value) + + assert Config.access_token(otp_app: :my_app) == :custom_value + end + + test "acess_grant/1" do + assert Config.access_grant(otp_app: :my_app) == MyApp.OauthAccessGrants.OauthAccessGrant + + Application.delete_env(:ex_oauth2_provider, ExOauth2Provider) + Application.put_env(:my_app, ExOauth2Provider, access_grant: :custom_value) + + assert Config.access_grant(otp_app: :my_app) == :custom_value + end + test "repo/1" do assert Config.repo(otp_app: :my_app) == Dummy.Repo