Skip to content

Commit d386364

Browse files
authored
Refactor API to use IOptions pattern with IConfigurationSection binding (#59)
* Refactor API to use IOptions pattern with IConfigurationSection binding * Update Documentation and Examples to work with the new public API signatures * Update docs-source to reflect the new Public API signatures * Adds Domain format validation and prevent EventsType bypass * Adds startup validation integration tests * Ensure trailing '/' in domain is tolerated * Update Migration.md to callout potential captive dependency * Improve DX with more extension methods for configuration
1 parent 79dd413 commit d386364

25 files changed

Lines changed: 1617 additions & 1046 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ docfx.zip
4848
# Ignoring Misc
4949
.DS_Store
5050
.github/.DS_Store
51+
52+
# Ignoring C# Dev Kit language service cache files
53+
*.lscache

Auth0.AspNetCore.Authentication.Api.Playground/Program.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,21 @@
1010
builder.Services.AddSwaggerGen();
1111

1212
// Adds Auth0 JWT validation to the API
13-
builder.Services.AddAuth0ApiAuthentication(options =>
14-
{
15-
options.JwtBearerOptions = new JwtBearerOptions
16-
{
17-
Audience = builder.Configuration["Auth0:Audience"]
18-
?? throw new InvalidOperationException("Auth0:Audience is required")
19-
};
20-
options.Domain = builder.Configuration["Auth0:Domain"]
21-
?? throw new InvalidOperationException("Auth0:Domain is required");
22-
options.JwtBearerOptions.Events = new JwtBearerEvents
13+
// Configuration is automatically bound from appsettings.json "Auth0" section
14+
builder.Services.AddAuth0ApiAuthentication(
15+
builder.Configuration.GetSection("Auth0"),
16+
configureJwtBearer: jwt =>
2317
{
24-
// Custom event just to log the token received in the request.
25-
OnMessageReceived = context =>
18+
jwt.Events = new JwtBearerEvents
2619
{
27-
Console.WriteLine($"Token extracted? : {(!string.IsNullOrEmpty(context.Token) ? "yes" : "no")}");
28-
return Task.CompletedTask;
29-
}
30-
};
31-
}).WithDPoP();
20+
// Custom event just to log the token received in the request.
21+
OnMessageReceived = context =>
22+
{
23+
Console.WriteLine($"Token extracted? : {(!string.IsNullOrEmpty(context.Token) ? "yes" : "no")}");
24+
return Task.CompletedTask;
25+
}
26+
};
27+
}).WithDPoP();
3228

3329
builder.Services.AddAuthorization();
3430

0 commit comments

Comments
 (0)