Skip to content

Commit

Permalink
Merge pull request #1460 from DuendeSoftware/joe/par-licensing
Browse files Browse the repository at this point in the history
Add license validation for PAR
  • Loading branch information
brockallen authored Nov 7, 2023
2 parents 983af93 + 2fb6496 commit d2facdc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 50 deletions.
47 changes: 0 additions & 47 deletions hosts/main/Program.cs.bak

This file was deleted.

14 changes: 14 additions & 0 deletions src/IdentityServer/Licensing/IdentityServerLicense.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ internal override void Initialize(ClaimsPrincipal claims)
KeyManagementFeature = true;
break;
}

ParFeature = claims.HasClaim("feature", "par");
switch (Edition)
{
case LicenseEdition.Enterprise:
case LicenseEdition.Business:
case LicenseEdition.Community:
ParFeature = true;
break;
}

ResourceIsolationFeature = claims.HasClaim("feature", "resource_isolation");
switch (Edition)
Expand Down Expand Up @@ -167,6 +177,10 @@ internal override void Initialize(ClaimsPrincipal claims)
/// </summary>
public bool KeyManagementFeature { get; set; }
/// <summary>
/// PAR
/// </summary>
public bool ParFeature { get; set; }
/// <summary>
/// Resource isolation
/// </summary>
public bool ResourceIsolationFeature { get; set; }
Expand Down
18 changes: 18 additions & 0 deletions src/IdentityServer/Licensing/IdentityServerLicenseValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@ public void ValidateResourceIndicators(string resourceIndicator)
}
}
}

bool ValidateParWarned = false;
public void ValidatePar()
{
if(License != null)
{
if(!License.ParFeature)
{
throw new Exception("A request was made to the pushed authorization endpoint. Your license of Duende IdentityServer does not permit pushed authorization. This features requires the Business Edition or higher tier of license.");
}
}
else if (!ValidateParWarned)
{
ValidateParWarned = true;
WarningLog?.Invoke("A request was made to the pushed authorization endpoint, but you do not have a license. This feature requires the Business Edition or higher tier of license.", Array.Empty<object>());
}
}

public void ValidateResourceIndicators(IEnumerable<string> resourceIndicators)
{
if (resourceIndicators?.Any() == true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Duende.IdentityServer.Validation;
/// cref="IAuthorizeRequestValidator"/> to validate the pushed parameters as if
/// they had been sent to the authorize endpoint directly.
/// </summary>
public class PushedAuthorizationRequestValidator : IPushedAuthorizationRequestValidator
internal class PushedAuthorizationRequestValidator : IPushedAuthorizationRequestValidator
{

private readonly IAuthorizeRequestValidator _authorizeRequestValidator;
Expand All @@ -36,6 +36,7 @@ public PushedAuthorizationRequestValidator(IAuthorizeRequestValidator authorizeR
/// <inheritdoc />
public async Task<PushedAuthorizationValidationResult> ValidateAsync(PushedAuthorizationRequestValidationContext context)
{
IdentityServerLicenseValidator.Instance.ValidatePar();
var validatedRequest = await ValidateRequestUriAsync(context);
if(validatedRequest.IsError)
{
Expand Down Expand Up @@ -63,7 +64,7 @@ public async Task<PushedAuthorizationValidationResult> ValidateAsync(PushedAutho
/// context.</param>
/// <returns>A task containing the <see
/// cref="PushedAuthorizationValidationResult"/>.</returns>
protected virtual Task<PushedAuthorizationValidationResult> ValidateRequestUriAsync(PushedAuthorizationRequestValidationContext context)
private Task<PushedAuthorizationValidationResult> ValidateRequestUriAsync(PushedAuthorizationRequestValidationContext context)
{
// Reject request_uri parameter
if (context.RequestParameters.Get(OidcConstants.AuthorizeRequest.RequestUri).IsPresent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void license_should_parse_edition_and_use_default_values()
//subject.BffFeature.Should().BeTrue();
subject.RedistributionFeature.Should().BeFalse();
subject.CibaFeature.Should().BeTrue();
subject.ParFeature.Should().BeTrue();
}
{
var subject = new IdentityServerLicense(new Claim("edition", "business"));
Expand All @@ -81,6 +82,7 @@ public void license_should_parse_edition_and_use_default_values()
//subject.BffFeature.Should().BeTrue();
subject.RedistributionFeature.Should().BeFalse();
subject.CibaFeature.Should().BeFalse();
subject.ParFeature.Should().BeTrue();
}
{
var subject = new IdentityServerLicense(new Claim("edition", "starter"));
Expand All @@ -97,6 +99,7 @@ public void license_should_parse_edition_and_use_default_values()
//subject.BffFeature.Should().BeFalse();
subject.RedistributionFeature.Should().BeFalse();
subject.CibaFeature.Should().BeFalse();
subject.ParFeature.Should().BeFalse();
}
{
var subject = new IdentityServerLicense(new Claim("edition", "community"));
Expand All @@ -113,6 +116,7 @@ public void license_should_parse_edition_and_use_default_values()
//subject.BffFeature.Should().BeTrue();
subject.RedistributionFeature.Should().BeFalse();
subject.CibaFeature.Should().BeTrue();
subject.ParFeature.Should().BeTrue();
}

// BFF
Expand Down Expand Up @@ -245,7 +249,8 @@ public void license_should_handle_overrides_for_default_edition_values()
new Claim("feature", "dpop"),
new Claim("feature", "bff"),
new Claim("feature", "ciba"),
new Claim("feature", "dynamic_providers"));
new Claim("feature", "dynamic_providers"),
new Claim("feature", "par"));
subject.ClientLimit.Should().Be(20);
subject.IssuerLimit.Should().Be(5);
subject.KeyManagementFeature.Should().BeTrue();
Expand All @@ -257,6 +262,7 @@ public void license_should_handle_overrides_for_default_edition_values()
subject.DynamicProvidersFeature.Should().BeTrue();
subject.RedistributionFeature.Should().BeTrue();
subject.CibaFeature.Should().BeTrue();
subject.ParFeature.Should().BeTrue();
}
{
var subject = new IdentityServerLicense(
Expand Down

0 comments on commit d2facdc

Please sign in to comment.