riverrun / phauxth

Not actively maintained - Authentication library for Phoenix, and other Plug-based, web applications
409 stars 21 forks source link

Add support for namespaced configurations #29

Closed guidotripaldi closed 7 years ago

guidotripaldi commented 7 years ago

A namespaced app name is required in the apps/my_app_name/config/config.exs file when Phauxth is used in an Umbrella project, where multiple apps are using the library.

This because in Umbrella projects the children apps configurations are merged together and the conflicting keys overridden, so we need to namespace every Phauxth configuration to avoid the override and to be able to retrieving the correct peculiar values for each child application.

riverrun commented 7 years ago

Looks good. Thanks!

I have just pushed a version with one small change (using Mix.Project.config) to master. Could you check that it works with your setup?

guidotripaldi commented 7 years ago

Yes, all tests succeeded. But I was too hasty in solving the solution. Namespacing the app name makes (of course!) the compiler warning that there isn't a library with that name:

You have configured application :phauxth_my_app_api in your configuration
file, but the application is not available.

This usually means one of:

1. You have not added the application as a dependency in a mix.exs file.

2. You are configuring an application that does not really exist.

Please ensure :phauxth_my_app_api exists or remove the configuration.

So namespacing the app name in the config works but it is not elegant. But namespacing is the only solution to circumvent the way Mix.Config.config/2 works. Another way could be namespacing the keys instead of the app name:

      config :phauxth,
        token_salt_my_app_name: "YkLmt7+f",
        endpoint_my_app_name: MyAppName.Endpoint

But maybe you have some better idea.

riverrun commented 7 years ago

Ok. First, I'll push this version to hex, and then we can look at other possible solutions later.

One idea I had was to use keyword arguments for the endpoint and / or token_salt. I am also looking at other ways to get the current app's endpoint.

guidotripaldi commented 7 years ago

For getting the app's endpoint, maybe I have a good idea. Let me try it first.

guidotripaldi commented 7 years ago

Yes, the idea works, I've open a PR with the new branch