Skip to content

Commit

Permalink
Merge pull request #61 from DuendeSoftware/dh/http-properties-warning
Browse files Browse the repository at this point in the history
Fix HttpRequestMethod.Properties obsolete warning
  • Loading branch information
damianh committed Nov 20, 2024
2 parents 8cd67d7 + ed05aee commit 23cd3ca
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task Http_request_should_have_correct_format()
};

request.Headers.Add("custom", "custom");
request.Properties.Add("custom", "custom");
request.GetProperties().Add("custom", "custom");

var response = await client.RequestBackchannelAuthenticationAsync(request);

Expand All @@ -59,7 +59,7 @@ public async Task Http_request_should_have_correct_format()
headers.Count().Should().Be(3);
headers.Should().Contain(h => h.Key == "custom" && h.Value.First() == "custom");

var properties = httpRequest.Properties;
var properties = httpRequest.GetProperties();
properties.Count.Should().Be(1);

var prop = properties.First();
Expand Down Expand Up @@ -133,7 +133,7 @@ public async Task Http_request_with_request_object_should_have_correct_format()
};

request.Headers.Add("custom", "custom");
request.Properties.Add("custom", "custom");
request.GetProperties().Add("custom", "custom");

var response = await client.RequestBackchannelAuthenticationAsync(request);

Expand All @@ -147,7 +147,7 @@ public async Task Http_request_with_request_object_should_have_correct_format()
headers.Count().Should().Be(3);
headers.Should().Contain(h => h.Key == "custom" && h.Value.First() == "custom");

var properties = httpRequest.Properties;
var properties = httpRequest.GetProperties();
properties.Count.Should().Be(1);

var prop = properties.First();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public async Task Request_without_body_should_have_correct_format()

var headers = httpRequest.Headers;
headers.Count().Should().Be(2);


}

[Fact]
Expand All @@ -56,7 +54,7 @@ public async Task Http_request_should_have_correct_format()
};

request.Headers.Add("custom", "custom");
request.Properties.Add("custom", "custom");
request.GetProperties().Add("custom", "custom");

var _ = await client.RequestDeviceAuthorizationAsync(request);

Expand All @@ -69,7 +67,7 @@ public async Task Http_request_should_have_correct_format()
headers.Count().Should().Be(3);
headers.Should().Contain(h => h.Key == "custom" && h.Value.First() == "custom");

var properties = httpRequest.Properties;
var properties = httpRequest.GetProperties();
properties.Count.Should().Be(1);

var prop = properties.First();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task Http_request_should_have_correct_format()
};

request.Headers.Add("custom", "custom");
request.Properties.Add("custom", "custom");
request.GetProperties().Add("custom", "custom");

var response = await client.GetDiscoveryDocumentAsync(request);

Expand All @@ -61,7 +61,7 @@ public async Task Http_request_should_have_correct_format()
headers.Count().Should().Be(2);
headers.Should().Contain(h => h.Key == "custom" && h.Value.First() == "custom");

var properties = httpRequest.Properties;
var properties = httpRequest.GetProperties();
properties.Count.Should().Be(1);

var prop = properties.First();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task Http_request_should_have_correct_format()
};

request.Headers.Add("custom", "custom");
request.Properties.Add("custom", "custom");
request.GetProperties().Add("custom", "custom");

var response = await client.RegisterClientAsync(request);

Expand All @@ -44,7 +44,7 @@ public async Task Http_request_should_have_correct_format()
headers.Count().Should().Be(2);
headers.Should().Contain(h => h.Key == "custom" && h.Value.First() == "custom");

var properties = httpRequest.Properties;
var properties = httpRequest.GetProperties();
properties.Count.Should().Be(1);

var prop = properties.First();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#if NETFRAMEWORK
using System.Net.Http;
#endif

namespace Duende.IdentityModel.HttpClientExtensions;

internal static class HttpRequestMethodExtensions
{
public static IDictionary<string, object> GetProperties(this HttpRequestMessage requestMessage)
{
#if NETFRAMEWORK
return requestMessage.Properties;
#else
return (IDictionary<string, object>)requestMessage.Options;
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task Http_request_should_have_correct_format()
};

request.Headers.Add("custom", "custom");
request.Properties.Add("custom", "custom");
request.GetProperties().Add("custom", "custom");

var response = await client.GetJsonWebKeySetAsync(request);

Expand All @@ -60,7 +60,7 @@ public async Task Http_request_should_have_correct_format()
headers.Count().Should().Be(2);
headers.Should().Contain(h => h.Key == "custom" && h.Value.First() == "custom");

var properties = httpRequest.Properties;
var properties = httpRequest.GetProperties();
properties.Count.Should().Be(1);

var prop = properties.First();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task Http_request_should_have_correct_format()
State = "5678"
};
request.Headers.Add("custom", "custom");
request.Properties.Add("custom", "custom");
request.GetProperties().Add("custom", "custom");

var response = await client.PushAuthorizationAsync(request);

Expand All @@ -52,7 +52,7 @@ public async Task Http_request_should_have_correct_format()
headers.Count().Should().Be(3);
headers.Should().Contain(h => h.Key == "custom" && h.Value.First() == "custom");

var properties = httpRequest.Properties;
var properties = httpRequest.GetProperties();
properties.Count.Should().Be(1);

var prop = properties.First();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task Http_request_should_have_correct_format()
};

request.Headers.Add("custom", "custom");
request.Properties.Add("custom", "custom");
request.GetProperties().Add("custom", "custom");

_ = await client.IntrospectTokenAsync(request);

Expand All @@ -42,7 +42,7 @@ public async Task Http_request_should_have_correct_format()
["Accept"] = new[] { "application/json" },
["custom"] = new[] { "custom" },
});
httpRequest.Properties.Should().BeEquivalentTo(new Dictionary<string, string>
httpRequest.GetProperties().Should().BeEquivalentTo(new Dictionary<string, string>
{
["custom"] = "custom",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task Http_request_should_have_correct_format()
};

request.Headers.Add("custom", "custom");
request.Properties.Add("custom", "custom");
request.GetProperties().Add("custom", "custom");

var _ = await client.RequestTokenAsync(request);
var httpRequest = handler.Request;
Expand All @@ -56,7 +56,7 @@ public async Task Http_request_should_have_correct_format()
headers.Count().Should().Be(3);
headers.Should().Contain(h => h.Key == "custom" && h.Value.First() == "custom");

var properties = httpRequest.Properties;
var properties = httpRequest.GetProperties();
properties.Count.Should().Be(1);

var prop = properties.First();
Expand Down Expand Up @@ -159,13 +159,13 @@ public async Task Additional_request_properties_should_be_propagated()
Scope = "scope"
};

request.Properties.Add("foo", "bar");
request.GetProperties().Add("foo", "bar");

var response = await _client.RequestClientCredentialsTokenAsync(request);

response.IsError.Should().BeFalse();

var properties = _handler.Request.Properties;
var properties = _handler.Request.GetProperties();
var foo = properties.First().Value as string;
foo.Should().NotBeNull();
foo.Should().Be("bar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task Http_request_should_have_correct_format()
};

request.Headers.Add("custom", "custom");
request.Properties.Add("custom", "custom");
request.GetProperties().Add("custom", "custom");

var response = await client.RevokeTokenAsync(request);

Expand All @@ -41,7 +41,7 @@ public async Task Http_request_should_have_correct_format()
headers.Count().Should().Be(2);
headers.Should().Contain(h => h.Key == "custom" && h.Value.First() == "custom");

var properties = httpRequest.Properties;
var properties = httpRequest.GetProperties();
properties.Count.Should().Be(1);

var prop = properties.First();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task Http_request_should_have_correct_format()
};

request.Headers.Add("custom", "custom");
request.Properties.Add("custom", "custom");
request.GetProperties().Add("custom", "custom");

var response = await client.GetUserInfoAsync(request);

Expand All @@ -60,7 +60,7 @@ public async Task Http_request_should_have_correct_format()
headers.Should().Contain(h => h.Key == "custom" && h.Value.First() == "custom");
headers.Should().Contain(h => h.Key == "Authorization" && h.Value.First() == "Bearer token");

var properties = httpRequest.Properties;
var properties = httpRequest.GetProperties();
properties.Count.Should().Be(1);

var prop = properties.First();
Expand Down

0 comments on commit 23cd3ca

Please sign in to comment.