Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpMethod property of DownstreamApiOptions fails to deserialize from appsettings. #2338

Open
MZOLN opened this issue Jul 21, 2023 · 2 comments
Labels
question Further information is requested

Comments

@MZOLN
Copy link

MZOLN commented Jul 21, 2023

Microsoft.Identity.Web Library

Microsoft.Identity.Web

Microsoft.Identity.Web version

2.11.1

Web app

Sign-in users

Web API

Protected web APIs call downstream web APIs

Token cache serialization

Not Applicable

Description

Deserialization of HttpMethod property of DownstreamApiOptions does not seem to work well.
Configuration system fails to deserialize System.Net.Http.HttpMethod from string, so my HttpMethod : "POST" always end up as a "GET".

Reproduction steps

For example, given settings like this:
"DownstreamApis":
"Api2Post": {
"BaseUrl": "https://fake.post.uri.microsoft.com/v1.0",
"RelativePath": "/me",
"Scopes": [ "https://fake.post.uri.microsoft.com/v1.0/me/user.read" ],
"HttpMethod": "POST",
"AcquireTokenOptions": {
"AuthenticationOptionsName": "S2SAuthentication"
}
}
}

deserializing with DI (that was my case):
services.Configure<Dictionary<string, DownstreamApiOptions>>(configuration.GetSection("DownstreamApis"));

Would result in still having the property value as a "GET"
Expected would be "POST"

Error message

No response

Id Web logs

No response

Relevant code snippets

Check the repro

Regression

No response

Expected behavior

HttpMethod property value deserialized as a provided value in appsettings.json.

@MZOLN MZOLN added the question Further information is requested label Jul 21, 2023
@MZOLN
Copy link
Author

MZOLN commented Jul 21, 2023

Workarounds exist:

  1. If not using DI read the configuration value directly
  2. Use PostConfigure if using DI:
services.PostConfigure<Dictionary<string, DownstreamApiOptions>>(downstreamApiOptions =>
{
     foreach (var downstreamApiOption in downstreamApiOptions)
     {
          string httpMethodString = configuration[$"DownstreamApis:{downstreamApiOption.Key}:HttpMethod"] ?? "GET";
          downstreamApiOption.Value.HttpMethod = new HttpMethod(httpMethodString);
     }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants