| 1 | # Api Authentication Configuration |
| 2 | |
| 3 | ## Decision |
| 4 | |
| 5 | A new extension will be introduced for configuring the `ApiAuthenticationRegistry` |
| 6 | |
| 7 | ## Rationale |
| 8 | |
| 9 | Recently, the `ApiAuthenticationRegistry` was introduced for associating a web context to a `AuthenticationService` in |
| 10 | order to use different auth mechanism for different contexts. Currently though, this association is expressed |
| 11 | in each `AuthenticationService` extension, which makes ti difficult to apply an `AuthenticationService` to a different |
| 12 | context compared to the current hardcoded one. |
| 13 | |
| 14 | ## Approach |
| 15 | |
| 16 | Each implementor of `AuthenticationService` will also implement an `ApiAuthenticationProvider` which will provide an |
| 17 | instance of `AuthenticationService` based on the input configuration. |
| 18 | |
| 19 | ```java |
| 20 | public interface ApiAuthenticationProvider { |
| 21 | |
| 22 | Result<AuthenticationService> provide(Config config); |
| 23 | } |
| 24 | ``` |
| 25 | |
| 26 | Those providers can be registered in a registry `ApiAuthenticationProviderRegistry`, associated with the auth type ( |
| 27 | basic,token, delegated, ...) |
| 28 | |
| 29 | ```java |
| 30 | public interface ApiAuthenticationProviderRegistry { |
| 31 | |
| 32 | void register(String type, ApiAuthenticationProvider provider); |
| 33 | |
| 34 | Result<ApiAuthenticationProvider> resolve(String type); |
| 35 | } |
| 36 | ``` |
| 37 | |
| 38 | Then the new extension, leveraging the partition mechanism of EDC `web.http` config, will configure the association |
| 39 | between the context and the auth type in the prepare phase. |
| 40 | |
| 41 | For example if a user wants to configure the `TokenBasedAuthenticationService` for the `management` context, a |
| 42 | configuration like this could be used: |
| 43 | |
| 44 | ``` |
| 45 | web.http.management.auth.type=tokenbased |
| 46 | web.http.management.auth.key.alias=vaultAlias |
| 47 | ``` |
| 48 | |
| 49 | For each web context the extension will read the `auth.type` if present, and will invoke the provider for that type with |
| 50 | the input configuration, associating then the created instance with the configured `context` in |
| 51 | the `ApiAuthenticationRegistry`. |
| 52 | |
| 53 | > For backward compatibility we will leave in place the current hardcoded association |
| 54 | > context <-> `AuthenticationService` |