Azure-Samples / Azure-Samples/active-directory-dotnetcore-daemon-v2

System.InvalidOperationException : An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set.

Open
#198 5 comments 0 reactions 0 assignees View on GitHub
answered question
Dominant language
PowerShell
Stars
263
Forks
162
PR merge metrics
No merged PRs in 30d

Description

> 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:///.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();
string result = await api.GetForAppAsync("MyAPI");

How can I troubleshoot this error?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.