SimpleIdServer icon indicating copy to clipboard operation
SimpleIdServer copied to clipboard

Bug: SCIM EnableApiKeyAuth incorrectly registers default ApiKeysConfiguration

Open dimOk00 opened this issue 7 months ago • 1 comments

There's a logical error in the EnableApiKeyAuth extension method. When a custom ApiKeysConfiguration is passed to the method, it's ignored, and the default configuration is registered instead.


Problematic Code

The current implementation checks if apiKeysConfiguration is not null and then proceeds to register the default configuration, which is the opposite of the intended behavior.

// from namespace SimpleIdServer.Scim.ScimBuilderExtensions

public static ScimBuilder EnableApiKeyAuth(this ScimBuilder builder, ApiKeysConfiguration? apiKeysConfiguration = null)
{
    // This condition is incorrect.
    if (apiKeysConfiguration != null)
      builder.Services.AddSingleton<ApiKeysConfiguration>(ApiKeysConfiguration.Default);
    else
      builder.Services.AddSingleton<ApiKeysConfiguration>(apiKeysConfiguration);

    // ... rest of the method
}

Expected vs. Actual Behavior

  • Expected Behavior: When a non-null apiKeysConfiguration object is provided, that specific instance should be registered in the service container.
  • Actual Behavior: The provided apiKeysConfiguration is ignored, and ApiKeysConfiguration.Default is registered in its place.

Proposed Solution ✅

The conditional logic should be inverted to prioritize the user-provided configuration. A more concise way to write this is with the null-coalescing operator (??).

Suggested Fix:

public static ScimBuilder EnableApiKeyAuth(this ScimBuilder builder, ApiKeysConfiguration? apiKeysConfiguration = null)
{
    builder.Services.AddSingleton<ApiKeysConfiguration>(apiKeysConfiguration ?? ApiKeysConfiguration.Default);

    // ... rest of the method
}

Contribution Guide Request

I would be happy to submit a pull request to resolve this. Could you provide any guidance on the process for making a PR?

Thank you!

dimOk00 avatar Jul 23 '25 12:07 dimOk00

Thank you for your suggestion to create a pull request, but this issue has already been fixed by another pull request 🙂: https://github.com/simpleidserver/SimpleIdServer/pull/904/files The changes are already present in the master branch and will be included in the 6.0.4 release.

simpleidserver avatar Jul 23 '25 12:07 simpleidserver