Add 2025-03-26 OAuth backward compatibility for client conformance (#1374)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
c57f917d63
commit
4e68a4e9ec
1 changed files with 291 additions and 30 deletions
|
|
@ -68,12 +68,15 @@ public sealed class Program
|
|||
public bool ClientIdMetadataDocumentSupported { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the authorization server requires a resource parameter.
|
||||
/// Gets or sets a value indicating whether the authorization server expects a resource parameter.
|
||||
/// When <c>true</c>, the resource parameter must be present and match a valid resource.
|
||||
/// When <c>false</c>, the resource parameter must be absent to simulate legacy servers that
|
||||
/// do not support RFC 8707 resource indicators.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The default value is <c>true</c>.
|
||||
/// </remarks>
|
||||
public bool RequireResource { get; set; } = true;
|
||||
public bool ExpectResource { get; set; } = true;
|
||||
|
||||
public HashSet<string> DisabledMetadataPaths { get; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public IReadOnlyCollection<string> MetadataRequests => _metadataRequests.ToArray();
|
||||
|
|
@ -297,8 +300,9 @@ public sealed class Program
|
|||
return Results.Redirect($"{redirect_uri}?error=invalid_request&error_description=Only+S256+code_challenge_method+is+supported&state={state}");
|
||||
}
|
||||
|
||||
// Validate resource in accordance with RFC 8707
|
||||
if (RequireResource && (string.IsNullOrEmpty(resource) || !ValidResources.Contains(resource)))
|
||||
// Validate resource in accordance with RFC 8707.
|
||||
// When ExpectResource is false, the resource parameter must be absent (legacy mode).
|
||||
if (ExpectResource ? (string.IsNullOrEmpty(resource) || !ValidResources.Contains(resource)) : !string.IsNullOrEmpty(resource))
|
||||
{
|
||||
return Results.Redirect($"{redirect_uri}?error=invalid_target&error_description=The+specified+resource+is+not+valid&state={state}");
|
||||
}
|
||||
|
|
@ -344,9 +348,10 @@ public sealed class Program
|
|||
type: "https://tools.ietf.org/html/rfc6749#section-5.2");
|
||||
}
|
||||
|
||||
// Validate resource in accordance with RFC 8707
|
||||
// Validate resource in accordance with RFC 8707.
|
||||
// When ExpectResource is false, the resource parameter must be absent (legacy mode).
|
||||
var resource = form["resource"].ToString();
|
||||
if (RequireResource && (string.IsNullOrEmpty(resource) || !ValidResources.Contains(resource)))
|
||||
if (ExpectResource ? (string.IsNullOrEmpty(resource) || !ValidResources.Contains(resource)) : !string.IsNullOrEmpty(resource))
|
||||
{
|
||||
return Results.BadRequest(new OAuthErrorResponse
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue