Skip to content

Commit d573882

Browse files
feature: this commit introduces the web host environment parameter to UseSpecification to customize the OAuth2 configuration according to the environment (production or development). It improves visual options in the documentation (title, hide templates, expand tags) and updates the call in Program.cs to pass the environment.
1 parent f5d79a0 commit d573882

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

Boundaries/Comanda.Orchestrator/Source/Comanda.Orchestrator.WebApi/Extensions/SpecificationExtension.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,39 @@ namespace Comanda.Orchestrator.WebApi.Extensions;
33
[ExcludeFromCodeCoverage(Justification = "contains only dependency injection registration with no business logic.")]
44
public static class SpecificationsExtension
55
{
6-
public static void UseSpecification(this IEndpointRouteBuilder app)
6+
public static void UseSpecification(this IEndpointRouteBuilder app, IWebHostEnvironment environment)
77
{
88
app.MapScalarApiReference(options =>
99
{
1010
options.DarkMode = false;
1111
options.HideDarkModeToggle = true;
1212
options.HideClientButton = true;
13+
options.HideModels = true;
14+
options.Servers = [];
1315

14-
options.WithTitle("Comanda Orchestrator");
15-
options.WithClassicLayout();
16+
options.WithTitle("Comanda Orchestrator | Reference");
17+
options.ExpandAllTags();
18+
19+
if (environment.IsProduction())
20+
{
21+
options.AddPreferredSecuritySchemes(SecuritySchemes.OAuth2);
22+
options.AddClientCredentialsFlow(SecuritySchemes.OAuth2, flow =>
23+
{
24+
flow.WithCredentialsLocation(CredentialsLocation.Body);
25+
});
26+
27+
return;
28+
}
29+
30+
var settings = app.ServiceProvider.GetService<ISettings>()!;
31+
32+
options.AddPreferredSecuritySchemes(SecuritySchemes.OAuth2);
33+
options.AddClientCredentialsFlow(SecuritySchemes.OAuth2, flow =>
34+
{
35+
flow.ClientId = settings.Federation.ClientId;
36+
flow.ClientSecret = settings.Federation.ClientSecret;
37+
flow.WithCredentialsLocation(CredentialsLocation.Body);
38+
});
1639
});
1740
}
1841
}

Boundaries/Comanda.Orchestrator/Source/Comanda.Orchestrator.WebApi/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ public partial class Program
55
private static async Task Main(string[] args)
66
{
77
var builder = WebApplication.CreateBuilder(args);
8+
9+
var environment = builder.Environment;
810
var configuration = builder.Configuration;
911

1012
builder.Services.AddInfrastructure(configuration);
@@ -20,7 +22,7 @@ private static async Task Main(string[] args)
2022
app.MapOpenApi();
2123

2224
app.UseHttpPipeline();
23-
app.UseSpecification();
25+
app.UseSpecification(environment);
2426

2527
await app.RunAsync();
2628
}

0 commit comments

Comments
 (0)