Skip to content

Refactor API to use IOptions pattern with IConfigurationSection binding#59

Merged
kailash-b merged 8 commits into
masterfrom
feat/SDK-8871
May 20, 2026
Merged

Refactor API to use IOptions pattern with IConfigurationSection binding#59
kailash-b merged 8 commits into
masterfrom
feat/SDK-8871

Conversation

@kailash-b
Copy link
Copy Markdown
Contributor

@kailash-b kailash-b commented May 18, 2026

✏️ Changes

This PR refactors the public API surface to adopt the ASP.NET Core IOptions pattern with IConfigurationSection binding, replacing the previous approach of eagerly-evaluated Action<Auth0ApiOptions> callbacks that required users to manually wire JwtBearerOptions inside Auth0ApiOptions.

Added:

  • Auth0ApiOptionsValidator — validates Domain is set via IValidateOptions<Auth0ApiOptions>
  • Auth0JwtBearerConfigureOptions — implements IConfigureNamedOptions<JwtBearerOptions> to resolve Auth0ApiOptions at options resolution time (not registration time)
  • Auth0JwtBearerOptionsValidator — validates audience is configured on the final JwtBearerOptions, supporting both single-audience and multi-audience (ValidAudiences) scenarios
  • New ServiceCollectionExtensions overloads accepting IConfigurationSection for direct appsettings.json binding

Modified:

  • Auth0ApiOptions — simplified to contain only Domain and Audience (removed JwtBearerOptions property)
  • Auth0ApiAuthenticationBuilder — no longer holds Auth0ApiOptions instance; stores only AuthenticationScheme and Services
  • AuthenticationBuilderExtensions — replaced Action<Auth0ApiOptions> parameter with Action<JwtBearerOptions>? configureJwtBearer; removed manual property copying in ConfigureJwtBearerOptions
  • JwtBearerEventsFactory / DPoPEventsFactory — now accept JwtBearerEvents? directly instead of Auth0ApiOptions
  • ServiceCollectionExtensions — delegate overloads now register options via services.Configure<Auth0ApiOptions> and delegate to the AuthenticationBuilder-based extension

Removed:

  • ConfigureJwtBearerOptions method (manual property-by-property copy)
  • ValidateAuth0ApiOptions method (replaced by IValidateOptions implementations)
  • WithDPoP overloads accepting authenticationScheme parameter (uses builder.AuthenticationScheme instead)

New public API usage:

// Configuration-section binding (recommended)
builder.Services.AddAuth0ApiAuthentication(
    builder.Configuration.GetSection("Auth0"),
    configureJwtBearer: jwt => { /* customize JwtBearerOptions */ }
).WithDPoP();

// Delegate-based
builder.Services.AddAuth0ApiAuthentication(
    options => { options.Domain = "tenant.auth0.com"; options.Audience = "https://api"; },
    configureJwtBearer: jwt => { /* customize */ }
);

🔗 References

🎯 Testing

  • This change adds unit test coverage

  • This change adds integration test coverage

  • This change has been tested on the latest version of the platform/language or why not

✅ Checklist

@kailash-b kailash-b changed the title Refactor API to use IOptions pattern Refactor API to use IOptions pattern with IConfigurationSection binding May 18, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 18, 2026

Codecov Report

❌ Patch coverage is 95.62500% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.67%. Comparing base (79dd413) to head (ade7c9b).

Files with missing lines Patch % Lines
...thentication.Api/Auth0JwtBearerConfigureOptions.cs 86.36% 3 Missing ⚠️
...uthentication.Api/Auth0ApiAuthenticationBuilder.cs 33.33% 2 Missing ⚠️
...thentication.Api/Auth0JwtBearerOptionsValidator.cs 95.83% 0 Missing and 1 partial ⚠️
...hentication.Api/AuthenticationBuilderExtensions.cs 97.22% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #59      +/-   ##
==========================================
+ Coverage   92.12%   92.67%   +0.55%     
==========================================
  Files          26       29       +3     
  Lines        1358     1433      +75     
  Branches      154      164      +10     
==========================================
+ Hits         1251     1328      +77     
- Misses         75       76       +1     
+ Partials       32       29       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kailash-b kailash-b marked this pull request as ready for review May 18, 2026 15:20
@kailash-b kailash-b requested a review from a team as a code owner May 18, 2026 15:20
@kailash-b kailash-b merged commit d386364 into master May 20, 2026
3 checks passed
@kailash-b kailash-b deleted the feat/SDK-8871 branch May 20, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants