System.InvalidOperationException : An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set.
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:
tokenAcquirerFactory.Configuration.GetSection("ThisDoesNotExist");
Now, I may be deserving of some error - but that error certainly seems like it is not the one I should be getting:
"MyApi": {
"BaseUrl": "https://localhost:5010/",
"RelativePath": "api/MyController/ThisMethod",
"RequestAppToken": true,
"Scopes": [ "api://yada-6e75f60a2ef7/.default" ] // . E.g. 'api://<API_APPLICATION_ID>/.default'
},
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?