|
|
|
@ -5,10 +5,9 @@ |
|
|
|
*/ |
|
|
|
|
|
|
|
using System.Net.Http.Json; |
|
|
|
using System.Text; |
|
|
|
using System.Text.Encodings.Web; |
|
|
|
using AngleSharp.Html.Parser; |
|
|
|
using Microsoft.Extensions.Primitives; |
|
|
|
using OpenIddict.Extensions; |
|
|
|
|
|
|
|
namespace OpenIddict.Validation.IntegrationTests; |
|
|
|
|
|
|
|
@ -235,71 +234,28 @@ public class OpenIddictValidationIntegrationTestClient : IAsyncDisposable |
|
|
|
|
|
|
|
private HttpRequestMessage CreateRequestMessage(OpenIddictRequest request, HttpMethod method, Uri uri) |
|
|
|
{ |
|
|
|
// Note: a dictionary is deliberately not used here to allow multiple parameters with the
|
|
|
|
// same name to be specified. While initially not allowed by the core OAuth2 specification,
|
|
|
|
// this is required for derived drafts like the OAuth2 token exchange specification.
|
|
|
|
var parameters = new List<KeyValuePair<string?, string?>>(); |
|
|
|
|
|
|
|
foreach (var parameter in request.GetParameters()) |
|
|
|
if (!uri.IsAbsoluteUri) |
|
|
|
{ |
|
|
|
// If the parameter is null or empty, send an empty value.
|
|
|
|
if (OpenIddictParameter.IsNullOrEmpty(parameter.Value)) |
|
|
|
{ |
|
|
|
parameters.Add(new KeyValuePair<string?, string?>(parameter.Key, string.Empty)); |
|
|
|
|
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
var values = (string?[]?) parameter.Value; |
|
|
|
if (values is not { Length: > 0 }) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var value in values) |
|
|
|
{ |
|
|
|
parameters.Add(new KeyValuePair<string?, string?>(parameter.Key, value)); |
|
|
|
} |
|
|
|
uri = new Uri(HttpClient.BaseAddress!, uri); |
|
|
|
} |
|
|
|
|
|
|
|
if (method == HttpMethod.Get && parameters.Count is not 0) |
|
|
|
var message = new HttpRequestMessage(method, uri); |
|
|
|
if (message.Method == HttpMethod.Get && request.Count is not 0) |
|
|
|
{ |
|
|
|
var builder = new StringBuilder(); |
|
|
|
|
|
|
|
foreach (var parameter in parameters) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(parameter.Key)) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (builder.Length is not 0) |
|
|
|
{ |
|
|
|
builder.Append('&'); |
|
|
|
} |
|
|
|
|
|
|
|
builder.Append(UrlEncoder.Default.Encode(parameter.Key)); |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(parameter.Value)) |
|
|
|
{ |
|
|
|
builder.Append('='); |
|
|
|
builder.Append(UrlEncoder.Default.Encode(parameter.Value)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!uri.IsAbsoluteUri) |
|
|
|
{ |
|
|
|
uri = new Uri(HttpClient.BaseAddress!, uri); |
|
|
|
} |
|
|
|
|
|
|
|
uri = new UriBuilder(uri) { Query = builder.ToString() }.Uri; |
|
|
|
message.RequestUri = OpenIddictHelpers.AddQueryStringParameters(message.RequestUri!, |
|
|
|
request.GetParameters().ToDictionary( |
|
|
|
parameter => parameter.Key, |
|
|
|
parameter => new StringValues((string?[]?) parameter.Value))); |
|
|
|
} |
|
|
|
|
|
|
|
var message = new HttpRequestMessage(method, uri); |
|
|
|
|
|
|
|
if (method != HttpMethod.Get) |
|
|
|
if (message.Method != HttpMethod.Get) |
|
|
|
{ |
|
|
|
message.Content = new FormUrlEncodedContent(parameters); |
|
|
|
message.Content = new FormUrlEncodedContent( |
|
|
|
from parameter in request.GetParameters() |
|
|
|
let values = (string?[]?) parameter.Value |
|
|
|
where values is not null |
|
|
|
from value in values |
|
|
|
select new KeyValuePair<string?, string?>(parameter.Key, value)); |
|
|
|
} |
|
|
|
|
|
|
|
return message; |
|
|
|
|