I'm trying to build a simple client for testing an internal authentication service. The main idea is to just have a simple tool for testing to ensure that this service is callable (and successfully authenticates) in each environment.
In any client application that calls this service, a few settings need to be defined in App.config
. The primary one that is used is AuthenticationService
which contains a value that is a URL to this remote auth service, which is read by a DLL that is included in the client. This URL is different for each environment (Dev, QA, Prod).
For Example:
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=12345" >
<section name="Authenticator.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=12345" requirePermission="false"/>
<section name="RemoteAuthenticator.TokenCache.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=12345" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<RemoteAuthenticator.Properties.Settings>
<setting name="AuthenticationService" serializeAs="String">
<value>https://environment-url</value>
</setting>
</RemoteAuthenticator.TokenCache.Properties.Settings>
</applicationSettings>
The problem I'm running into is building a client that is able to call the service in different environments for testing. The value for the URL in the setting AuthenticationService
needs to be changed at runtime when the user makes requests to different environemnts, but I have been unable to find a way to do this.
The client DLL used to call this service provides the following way to add an auth token to an HttpClient
:
new AuthorizationHelper().AddAuthorization(httpClient);
These methods from the DLL call the service (at the URL specified within the client App.config
, and add the returned auth token to a header within the provided HttpClient
.
That is the extent of how this service is called, as the target environment URL from App.config
is read by the DLL when this is called. These methods in the DLL are basically a blackbox for me, as I have no way to modify how the URL is retrieved.
So far I have tried accessing this setting directly and via a ConfigurationManager
, but both ways show zero settings. After messing around with that for awhile, I tried creating multiple App.config
files, one for each environment, and attempted to re-load them at runtime as needed (as outlined in this post: https://stackoverflow.com/a/6151688/1428743). This last solution somewhat works, but only for the first call. Any successive calls to a different environement do not use the URL from the reloaded config, just the URL from the config loaded before the first call to the service.
Is there any way I can modify this setting at runtime in order to call different environments with this tool as needed?