You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
System.InvalidOperationException : An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set.
#198
Open
sam-wheat opened this issue
Jul 1, 2024
· 5 comments
BaseUrl is provided and the RelativePath component is valid - even if it is invalid it is not malformed.
IConfiguration appSettings = new ConfigurationBuilder().AddJsonFile(configFilePath, false).Build();
var tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance();
tokenAcquirerFactory.Services.AddDownstreamApi("MyApi", appSettings);
tokenAcquirerFactory.Configuration.GetSection("MyApi");
var sp = tokenAcquirerFactory.Build();
var api = sp.GetRequiredService<IDownstreamApi>();
string result = await api.GetForAppAsync<string>("MyAPI");
How can I troubleshoot this error?
The text was updated successfully, but these errors were encountered:
- IConfiguration appSettings = new ConfigurationBuilder().AddJsonFile(configFilePath, false).Build();
var tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance();
- tokenAcquirerFactory.Services.AddDownstreamApi("MyApi", appSettings);+ tokenAcquirerFactory.Services.AddDownstreamApi("MyApi", tokenAcquirerFactory.Configuration.GetSection("MyApi"));
var sp = tokenAcquirerFactory.Build();
var api = sp.GetRequiredService<IDownstreamApi>();
string result = await api.GetForAppAsync<string>("MyAPI");
but you also need an "AzureAd" section unless you want to use Managed identity
My config file does not exist in the bin folder so I create it manually and pass it to AddDownstreamApi:
IConfiguration appSettings = new ConfigurationBuilder().AddJsonFile(configFilePath, false).Build();
The config file does have an AzureAd section. Are you saying that is what is causing the problem? If so, how can I use a config file that does not get copied to bin (secrets file)? In prod it will get copied - however in dev the config file is not source controlled so I hardcode a path and load it as shown.
This seems to be the default error message and it appears it gets thrown regardless of what error actually occurs.
For example I can shut down my api server and rather than get a 404 I get the error above.
I can also intentionally provide an invalid section name for the api config and I get the same error:
Now, I may be deserving of some error - but that error certainly seems like it is not the one I should be getting:
BaseUrl is provided and the
RelativePath
component is valid - even if it is invalid it is not malformed.How can I troubleshoot this error?
The text was updated successfully, but these errors were encountered: