Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
550 changes: 275 additions & 275 deletions Directory.Packages.props

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<MvcBuildViews>false</MvcBuildViews>
<ImplicitUsings>disable</ImplicitUsings>
<NoWarn>CA3147</NoWarn>
<IncludePolyfills>false</IncludePolyfills>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<MvcBuildViews>false</MvcBuildViews>
<ImplicitUsings>disable</ImplicitUsings>
<NoWarn>CA3147</NoWarn>
<IncludePolyfills>false</IncludePolyfills>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
foreach (var parameter in string.Equals(Request.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) ?
from name in Request.Form.AllKeys
from value in Request.Form.GetValues(name)
select new KeyValuePair<string, string>(name, value) :
select KeyValuePair.Create(name, value) :
from name in Request.QueryString.AllKeys
from value in Request.QueryString.GetValues(name)
select new KeyValuePair<string, string>(name, value))
select KeyValuePair.Create(name, value))
{
<input type="hidden" name="@parameter.Key" value="@parameter.Value" />
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
foreach (var parameter in string.Equals(Request.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) ?
from name in Request.Form.AllKeys
from value in Request.Form.GetValues(name)
select new KeyValuePair<string, string>(name, value) :
select KeyValuePair.Create(name, value) :
from name in Request.QueryString.AllKeys
from value in Request.QueryString.GetValues(name)
select new KeyValuePair<string, string>(name, value))
select KeyValuePair.Create(name, value))
{
<input type="hidden" name="@parameter.Key" value="@parameter.Value" />
}
Expand Down
4 changes: 2 additions & 2 deletions shared/OpenIddict.Extensions/OpenIddictHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ public FormReader(Stream stream, Encoding encoding)
ReadNextPairImpl();
if (ReadSucceeded())
{
return new KeyValuePair<string, string>(_currentKey, _currentValue);
return KeyValuePair.Create(_currentKey, _currentValue);
}
return null;
}
Expand All @@ -1220,7 +1220,7 @@ private void ReadNextPairImpl()
await ReadNextPairAsyncImpl(cancellationToken);
if (ReadSucceeded())
{
return new KeyValuePair<string, string>(_currentKey, _currentValue);
return KeyValuePair.Create(_currentKey, _currentValue);
}
return null;
}
Expand Down
10 changes: 0 additions & 10 deletions shared/OpenIddict.Extensions/OpenIddictPolyfills.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,6 @@ public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build =
#endif
}

extension(ValueTask)
{
#if !SUPPORTS_VALUETASK_COMPLETED_TASK
/// <summary>
/// Gets a task that has already completed successfully.
/// </summary>
public static ValueTask CompletedTask => default;
#endif
}

extension<TResult>(ValueTask<TResult>)
{
#if !SUPPORTS_VALUETASK_COMPLETED_TASK
Expand Down
37 changes: 34 additions & 3 deletions src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,37 @@ public OpenIddictMessage(IEnumerable<KeyValuePair<string, string?>> parameters)
/// </summary>
/// <param name="parameters">The message parameters.</param>
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(IEnumerable<KeyValuePair<string, ImmutableArray<string?>>> parameters)
{
ArgumentNullException.ThrowIfNull(parameters);

foreach (var parameter in parameters)
{
// Ignore parameters whose name is null or empty.
if (string.IsNullOrEmpty(parameter.Key))
{
continue;
}

// Note: the core OAuth 2.0 specification requires that request parameters
// not be present more than once but derived specifications like the
// token exchange specification deliberately allow specifying multiple
// parameters with the same name to represent a multi-valued parameter.
AddParameter(parameter.Key, parameter.Value switch
{
{ IsDefaultOrEmpty: true } => default,
[string value] => new OpenIddictParameter(value),
[..] values => new OpenIddictParameter(values)
});
}
}

/// <summary>
/// Initializes a new OpenIddict message.
/// </summary>
/// <param name="parameters">The message parameters.</param>
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
public OpenIddictMessage(IEnumerable<KeyValuePair<string, ImmutableArray<string?>?>> parameters)
{
ArgumentNullException.ThrowIfNull(parameters);
Expand All @@ -170,9 +201,9 @@ public OpenIddictMessage(IEnumerable<KeyValuePair<string, ImmutableArray<string?
// parameters with the same name to represent a multi-valued parameter.
AddParameter(parameter.Key, parameter.Value switch
{
null or [] => default,
[string value] => new OpenIddictParameter(value),
[..] values => new OpenIddictParameter(values)
null or { IsDefaultOrEmpty: true } => default,
[string value] => new OpenIddictParameter(value),
[..] values => new OpenIddictParameter(values)
});
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/OpenIddict.Abstractions/Primitives/OpenIddictRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ public OpenIddictRequest(IEnumerable<KeyValuePair<string, string?>> parameters)
/// </summary>
/// <param name="parameters">The request parameters.</param>
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictRequest(IEnumerable<KeyValuePair<string, ImmutableArray<string?>>> parameters)
: base(parameters)
{
}

/// <summary>
/// Initializes a new OpenIddict request.
/// </summary>
/// <param name="parameters">The request parameters.</param>
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
public OpenIddictRequest(IEnumerable<KeyValuePair<string, ImmutableArray<string?>?>> parameters)
: base(parameters)
{
Expand Down
11 changes: 11 additions & 0 deletions src/OpenIddict.Abstractions/Primitives/OpenIddictResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ public OpenIddictResponse(IEnumerable<KeyValuePair<string, string?>> parameters)
/// </summary>
/// <param name="parameters">The response parameters.</param>
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictResponse(IEnumerable<KeyValuePair<string, ImmutableArray<string?>>> parameters)
: base(parameters)
{
}

/// <summary>
/// Initializes a new OpenIddict response.
/// </summary>
/// <param name="parameters">The response parameters.</param>
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
public OpenIddictResponse(IEnumerable<KeyValuePair<string, ImmutableArray<string?>?>> parameters)
: base(parameters)
{
Expand Down
4 changes: 2 additions & 2 deletions src/OpenIddict.Client.Owin/OpenIddictClientOwinHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public async ValueTask HandleAsync(TContext context)
context.Transaction.Request = new OpenIddictRequest(
from parameter in request.Query
let values = new StringValues(parameter.Value)
select new KeyValuePair<string, StringValues>(parameter.Key, values));
select KeyValuePair.Create(parameter.Key, values));
}

else if (string.Equals(request.Method, "POST", StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -279,7 +279,7 @@ from parameter in request.Query
context.Transaction.Request = new OpenIddictRequest(
from parameter in await request.ReadFormAsync()
let values = new StringValues(parameter.Value)
select new KeyValuePair<string, StringValues>(parameter.Key, values));
select KeyValuePair.Create(parameter.Key, values));
}

else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ from parameter in context.Transaction.Request.GetParameters()
let values = (ImmutableArray<string?>?) parameter.Value
where values is not null
from value in values.GetValueOrDefault()
select new KeyValuePair<string?, string?>(parameter.Key, value));
select KeyValuePair.Create(parameter.Key, value));
}

return ValueTask.CompletedTask;
Expand Down Expand Up @@ -1590,7 +1590,7 @@ public ValueTask HandleAsync(TContext context)
value = parameter[start..index].Trim();
}

yield return new KeyValuePair<string, string?>(key, value);
yield return KeyValuePair.Create<string, string?>(key, value);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public ValueTask HandleAsync(TContext context)
context.Transaction.Request = new OpenIddictRequest(
from parameter in request.Query
let values = new StringValues(parameter.Value)
select new KeyValuePair<string, StringValues>(parameter.Key, values));
select KeyValuePair.Create(parameter.Key, values));
}

else
Expand Down Expand Up @@ -544,7 +544,7 @@ public async ValueTask HandleAsync(TContext context)
context.Transaction.Request = new OpenIddictRequest(
from parameter in request.Query
let values = new StringValues(parameter.Value)
select new KeyValuePair<string, StringValues>(parameter.Key, values));
select KeyValuePair.Create(parameter.Key, values));
}

else if (string.Equals(request.Method, "POST", StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -578,7 +578,7 @@ from parameter in request.Query
context.Transaction.Request = new OpenIddictRequest(
from parameter in await request.ReadFormAsync()
let values = new StringValues(parameter.Value)
select new KeyValuePair<string, StringValues>(parameter.Key, values));
select KeyValuePair.Create(parameter.Key, values));
}

else
Expand Down Expand Up @@ -653,7 +653,7 @@ public async ValueTask HandleAsync(TContext context)
context.Transaction.Request = new OpenIddictRequest(
from parameter in await request.ReadFormAsync()
let values = new StringValues(parameter.Value)
select new KeyValuePair<string, StringValues>(parameter.Key, values));
select KeyValuePair.Create(parameter.Key, values));
}

else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ from parameter in context.Transaction.Request.GetParameters()
let values = (ImmutableArray<string?>?) parameter.Value
where values is not null
from value in values.GetValueOrDefault()
select new KeyValuePair<string?, string?>(parameter.Key, value));
select KeyValuePair.Create(parameter.Key, value));
}

return ValueTask.CompletedTask;
Expand Down Expand Up @@ -990,7 +990,7 @@ public ValueTask HandleAsync(TContext context)
value = parameter[start..index].Trim();
}

yield return new KeyValuePair<string, string?>(key, value);
yield return KeyValuePair.Create<string, string?>(key, value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public void Constructor_ThrowsAnExceptionForDuplicateParameters()
{
return new OpenIddictMessage(
[
new KeyValuePair<string, OpenIddictParameter>("parameter", "Fabrikam"),
new KeyValuePair<string, OpenIddictParameter>("parameter", "Contoso")
KeyValuePair.Create("parameter", new OpenIddictParameter("Fabrikam")),
KeyValuePair.Create("parameter", new OpenIddictParameter("Contoso"))
]);
});

Expand All @@ -51,7 +51,7 @@ public void Constructor_ImportsParameters()
// Arrange and act
var message = new OpenIddictMessage(
[
new KeyValuePair<string, OpenIddictParameter>("parameter", 42)
KeyValuePair.Create("parameter", new OpenIddictParameter(42))
]);

// Assert
Expand All @@ -66,7 +66,7 @@ public void Constructor_IgnoresNullOrEmptyParameterNames(string? name)
// Arrange and act
var message = new OpenIddictMessage(
[
new KeyValuePair<string, OpenIddictParameter>(name!, "Fabrikam")
KeyValuePair.Create(name!, new OpenIddictParameter("Fabrikam"))
]);

// Assert
Expand All @@ -79,8 +79,8 @@ public void Constructor_PreservesEmptyParameters()
// Arrange and act
var message = new OpenIddictMessage(
[
new KeyValuePair<string, OpenIddictParameter>("null-parameter", (string?) null),
new KeyValuePair<string, OpenIddictParameter>("empty-parameter", string.Empty)
KeyValuePair.Create("null-parameter", new OpenIddictParameter((string?) null)),
KeyValuePair.Create("empty-parameter", new OpenIddictParameter(string.Empty))
]);

// Assert
Expand All @@ -93,8 +93,8 @@ public void Constructor_CombinesDuplicateParameters()
// Arrange and act
var message = new OpenIddictMessage(
[
new KeyValuePair<string, string?>("parameter", "Fabrikam"),
new KeyValuePair<string, string?>("parameter", "Contoso")
KeyValuePair.Create<string, string?>("parameter", "Fabrikam"),
KeyValuePair.Create<string, string?>("parameter", "Contoso")
]);

// Assert
Expand All @@ -109,7 +109,7 @@ public void Constructor_SupportsMultiValuedParameters()
// Arrange and act
var message = new OpenIddictMessage(
[
new KeyValuePair<string, ImmutableArray<string?>?>("parameter", ["Fabrikam", "Contoso"])
KeyValuePair.Create<string, ImmutableArray<string?>>("parameter", ["Fabrikam", "Contoso"])
]);

// Assert
Expand All @@ -124,7 +124,7 @@ public void Constructor_ExtractsSingleValuedParameters()
// Arrange and act
var message = new OpenIddictMessage(
[
new KeyValuePair<string, ImmutableArray<string?>?>("parameter", ["Fabrikam"])
KeyValuePair.Create<string, ImmutableArray<string?>>("parameter", ["Fabrikam"])
]);

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,7 @@ void ConfigurePipeline(IApplicationBuilder app)
}

var claims = result.Principal.Claims.GroupBy(claim => claim.Type)
.Select(group => new KeyValuePair<string, ImmutableArray<string?>?>(
group.Key, group.Select(claim => claim.Value).ToImmutableArray<string?>()));
.Select(group => KeyValuePair.Create(group.Key, group.Select(claim => claim.Value).ToImmutableArray<string?>()));

context.Response.ContentType = "application/json";
await context.Response.WriteAsync(JsonSerializer.Serialize(new OpenIddictResponse(claims)));
Expand Down
Loading