Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease extension of DCR classes with protected props #1464

Merged
merged 1 commit into from
Nov 8, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ namespace Duende.IdentityServer.Configuration.RequestProcessing;
/// <inheritdoc />
public class DynamicClientRegistrationRequestProcessor : IDynamicClientRegistrationRequestProcessor
{
private readonly IdentityServerConfigurationOptions _options;
private readonly IClientConfigurationStore _store;
/// <summary>
/// The options.
/// </summary>
protected readonly IdentityServerConfigurationOptions Options;

/// <summary>
/// The client configuration store.
/// </summary>
protected readonly IClientConfigurationStore Store;

/// <summary>
/// Initializes a new instance of the <see cref="DynamicClientRegistrationRequestProcessor"/> class.
Expand All @@ -25,8 +32,8 @@ public DynamicClientRegistrationRequestProcessor(
IdentityServerConfigurationOptions options,
IClientConfigurationStore store)
{
_options = options;
_store = store;
Options = options;
Store = store;
}


Expand Down Expand Up @@ -57,7 +64,7 @@ public virtual async Task<IDynamicClientRegistrationResponse> ProcessAsync(
}
}

await _store.AddAsync(context.Client);
await Store.AddAsync(context.Client);

return new DynamicClientRegistrationResponse(context.Request, context.Client)
{
Expand Down Expand Up @@ -110,7 +117,7 @@ protected virtual async Task<IStepResult> AddClientSecret(
DynamicClientRegistrationContext context)
{
var plainText = CryptoRandom.CreateUniqueId();
DateTime? lifetime = _options.DynamicClientRegistration.SecretLifetime switch
DateTime? lifetime = Options.DynamicClientRegistration.SecretLifetime switch
{
null => null,
TimeSpan t => DateTime.UtcNow.Add(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ public class DynamicClientRegistrationResponseGenerator : IDynamicClientRegistra
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
};

private readonly ILogger<DynamicClientRegistrationResponseGenerator> _logger;
/// <summary>
/// The logger.
/// </summary>
protected readonly ILogger<DynamicClientRegistrationResponseGenerator> Logger;

/// <inheritdoc/>
public DynamicClientRegistrationResponseGenerator(ILogger<DynamicClientRegistrationResponseGenerator> logger)
{
_logger = logger;
Logger = logger;
}

/// <inheritdoc/>
Expand All @@ -41,7 +44,7 @@ public virtual async Task WriteResponse<T>(HttpContext context, int statusCode,
/// <inheritdoc/>
public virtual Task WriteContentTypeError(HttpContext context)
{
_logger.LogDebug("Invalid content type in dynamic client registration request");
Logger.LogDebug("Invalid content type in dynamic client registration request");
context.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType;
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ namespace Duende.IdentityServer.Configuration.Validation.DynamicClientRegistrati
/// <inheritdoc/>
public class DynamicClientRegistrationValidator : IDynamicClientRegistrationValidator
{
private readonly ILogger<DynamicClientRegistrationValidator> _logger;
/// <summary>
/// The logger.
/// </summary>
protected readonly ILogger<DynamicClientRegistrationValidator> Logger;

/// <summary>
/// Initializes a new instance of the <see cref="DynamicClientRegistrationValidator"/> class.
/// </summary>
public DynamicClientRegistrationValidator(
ILogger<DynamicClientRegistrationValidator> logger)
{
_logger = logger;
Logger = logger;
}

/// <inheritdoc/>
Expand Down Expand Up @@ -274,7 +277,7 @@ protected virtual Task<IStepResult> SetScopesAsync(DynamicClientRegistrationCont
if (scopes.Contains("offline_access"))
{
scopes = scopes.Where(s => s != "offline_access").ToArray();
_logger.LogDebug("offline_access should not be passed as a scope to dynamic client registration. Use the refresh_token grant_type instead.");
Logger.LogDebug("offline_access should not be passed as a scope to dynamic client registration. Use the refresh_token grant_type instead.");
}

foreach (var scope in scopes)
Expand All @@ -297,7 +300,7 @@ protected virtual Task<IStepResult> SetScopesAsync(DynamicClientRegistrationCont
/// represents that this step succeeded or failed.</returns>
protected virtual Task<IStepResult> SetDefaultScopes(DynamicClientRegistrationContext context)
{
_logger.LogDebug("No scopes requested for dynamic client registration, and no default scope behavior implemented. To set default scopes, extend the DynamicClientRegistrationValidator and override the SetDefaultScopes method.");
Logger.LogDebug("No scopes requested for dynamic client registration, and no default scope behavior implemented. To set default scopes, extend the DynamicClientRegistrationValidator and override the SetDefaultScopes method.");
return StepResult.Success();
}

Expand Down Expand Up @@ -365,12 +368,12 @@ protected virtual Task<IStepResult> SetSecretsAsync(DynamicClientRegistrationCon
}
catch (InvalidOperationException ex)
{
_logger.LogError(ex, "Failed to parse jwk");
Logger.LogError(ex, "Failed to parse jwk");
return StepResult.Failure("malformed jwk");
}
catch (JsonException ex)
{
_logger.LogError(ex, "Failed to parse jwk");
Logger.LogError(ex, "Failed to parse jwk");
return StepResult.Failure("malformed jwk");
}

Expand Down