Skip to content
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
116 changes: 61 additions & 55 deletions MessagingService/Bootstrapper/MiddlewareRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,61 +43,9 @@ public MiddlewareRegistry() {
failureStatus: HealthStatus.Unhealthy,
tags: new string[] { "db", "eventstore" });

this.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Messaging API",
Version = "1.0",
Description = "A REST Api to manage sending of various messages over different formats, currently only Email and SMS are supported.",
Contact = new OpenApiContact
{
Name = "Stuart Ferguson",
Email = "golfhandicapping@btinternet.com"
}
});
// add a custom operation filter which sets default values
c.OperationFilter<SwaggerDefaultValues>();
c.ExampleFilters();

//Locate the XML files being generated by ASP.NET...
var directory = new DirectoryInfo(AppContext.BaseDirectory);
var xmlFiles = directory.GetFiles("*.xml");

//... and tell Swagger to use those XML comments.
foreach (FileInfo fileInfo in xmlFiles)
{
c.IncludeXmlComments(fileInfo.FullName);
}
});

this.AddSwaggerExamplesFromAssemblyOf<SwaggerJsonConverter>();

this.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.BackchannelHttpHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback =
(message, certificate, chain, sslPolicyErrors) => true
};
options.Authority = GetSecurityConfigSetting("Authority");
options.Audience = GetSecurityConfigSetting("ApiName");

options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
{
ValidateAudience = false,
ValidAudience = GetSecurityConfigSetting("ApiName"),
ValidIssuer = GetSecurityConfigSetting("Authority"),
};
options.IncludeErrorDetails = true;
});

this.ConfigureAuthentication();
this.ConfigureSwagger();

this.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
Expand All @@ -118,5 +66,63 @@ public MiddlewareRegistry() {

this.AddSingleton(config);
}

private void ConfigureAuthentication() {
this.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.BackchannelHttpHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback =
(message, certificate, chain, sslPolicyErrors) => true
};
options.Authority = GetSecurityConfigSetting("Authority");
options.Audience = GetSecurityConfigSetting("ApiName");

options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
{
ValidateAudience = false,
ValidAudience = GetSecurityConfigSetting("ApiName"),
ValidIssuer = GetSecurityConfigSetting("Authority"),
};
options.IncludeErrorDetails = true;
});
}
private void ConfigureSwagger() {
this.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Messaging API",
Version = "1.0",
Description = "A REST Api to manage sending of various messages over different formats, currently only Email and SMS are supported.",
Contact = new OpenApiContact
{
Name = "Stuart Ferguson",
Email = "golfhandicapping@btinternet.com"
}
});
// add a custom operation filter which sets default values
c.OperationFilter<SwaggerDefaultValues>();
c.ExampleFilters();

//Locate the XML files being generated by ASP.NET...
var directory = new DirectoryInfo(AppContext.BaseDirectory);
var xmlFiles = directory.GetFiles("*.xml");

//... and tell Swagger to use those XML comments.
foreach (FileInfo fileInfo in xmlFiles)
{
c.IncludeXmlComments(fileInfo.FullName);
}
});

this.AddSwaggerExamplesFromAssemblyOf<SwaggerJsonConverter>();
}
}
}
2 changes: 1 addition & 1 deletion MessagingService/Controllers/DomainEventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private String ValidateEvent(String domainEventJson) {
/// <summary>
/// The controller name
/// </summary>
public const String ControllerName = "domainevents";
private const String ControllerName = "domainevents";

/// <summary>
/// The controller route
Expand Down
2 changes: 1 addition & 1 deletion MessagingService/Controllers/EmailController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private FileType ConvertFileType(DataTransferObjects.FileType emailAttachmentFil
/// <summary>
/// The controller name
/// </summary>
public const String ControllerName = "email";
private const String ControllerName = "email";

/// <summary>
/// The controller route
Expand Down
2 changes: 1 addition & 1 deletion MessagingService/Controllers/SMSController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public async Task<IActionResult> ResendSMS([FromBody] ResendSMSRequest resendSMS
/// <summary>
/// The controller name
/// </summary>
public const String ControllerName = "sms";
private const String ControllerName = "sms";

/// <summary>
/// The controller route
Expand Down
Loading