Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,6 @@ UploadedFiles
#Nuke working directory
.nuke-working-directory
/src/API/CompanyName.MyMeetings.API/tempkey.jwk

# CodeRush personal settings
*/.cr/personal
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DocumentationFile>bin\Debug\CompanyName.MyMeetings.API.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
</ItemGroup>
</Project>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using CompanyName.MyMeetings.BuildingBlocks.Application;
using System.Security.Claims;
using CompanyName.MyMeetings.BuildingBlocks.Application;

namespace CompanyName.MyMeetings.API.Configuration.ExecutionContext
{
public class ExecutionContextAccessor : IExecutionContextAccessor
internal class ExecutionContextAccessor : IExecutionContextAccessor
{
private readonly IHttpContextAccessor _httpContextAccessor;

Expand All @@ -19,11 +20,11 @@ public Guid UserId
.HttpContext?
.User?
.Claims?
.SingleOrDefault(x => x.Type == "sub")?
.SingleOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?
.Value != null)
{
return Guid.Parse(_httpContextAccessor.HttpContext.User.Claims.Single(
x => x.Type == "sub").Value);
x => x.Type == ClaimTypes.NameIdentifier).Value);
}

throw new ApplicationException("User context is not available");
Expand All @@ -34,11 +35,11 @@ public Guid CorrelationId
{
get
{
if (IsAvailable && _httpContextAccessor.HttpContext.Request.Headers.Keys.Any(
if (IsAvailable && _httpContextAccessor.HttpContext!.Request.Headers.Keys.Any(
x => x == CorrelationMiddleware.CorrelationHeaderKey))
{
return Guid.Parse(
_httpContextAccessor.HttpContext.Request.Headers[CorrelationMiddleware.CorrelationHeaderKey]);
_httpContextAccessor.HttpContext!.Request.Headers[CorrelationMiddleware.CorrelationHeaderKey]!);
}

throw new ApplicationException("Http context and correlation id is not available");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Reflection;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.ModuleHosting;
using Microsoft.OpenApi.Models;

namespace CompanyName.MyMeetings.API.Configuration.Extensions
{
internal static class SwaggerExtensions
{
internal static IServiceCollection AddSwaggerDocumentation(this IServiceCollection services)
internal static IServiceCollection AddSwaggerDocumentation(this IServiceCollection services, ModuleLoader moduleLoader)
{
services.AddSwaggerGen(options =>
{
Expand All @@ -22,32 +23,7 @@ internal static IServiceCollection AddSwaggerDocumentation(this IServiceCollecti
var commentsFile = Path.Combine(baseDirectory, commentsFileName);
options.IncludeXmlComments(commentsFile);

options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description =
"JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey
});

options.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
},
Scheme = "oauth2",
Name = "Bearer",
In = ParameterLocation.Header
},
new List<string>()
}
});
moduleLoader.ConfigureSwaggerModules(options);
});

return services;
Expand All @@ -62,4 +38,4 @@ internal static IApplicationBuilder UseSwaggerDocumentation(this IApplicationBui
return app;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.ModuleHosting;
using IdentityServerUserAccess = CompanyName.MyMeetings.Modules.UserAccess.Infrastructure.Configuration.ModuleHosting;
using MicrosoftIdentityUserAccess = CompanyName.MyMeetings.Modules.UsersMI.Infrastructure.Configuration.ModuleHosting;

namespace CompanyName.MyMeetings.API.Configuration;

internal static class UserAccessModuleSelector
{
private const string IdentityServerModuleType = "IdentityServer";
private const string MicrosoftIdentityModuleType = "MicrosoftIdentity";

private static readonly string[] AcceptedModuleTypes = [IdentityServerModuleType, MicrosoftIdentityModuleType];

public static void AddUserAccessModule(ModuleLoader moduleLoader, IConfiguration configuration)
{
var userModule = configuration["Modules:UserModule"];
if (string.IsNullOrWhiteSpace(userModule) || !AcceptedModuleTypes.Contains(userModule))
{
throw new InvalidOperationException($"Invalid user module configuration. Accepted values are: {string.Join(", ", AcceptedModuleTypes)}");
}

if (userModule == IdentityServerModuleType)
{
moduleLoader.AddModule(new IdentityServerUserAccess.UserAccessModule(configuration));
return;
}

if (userModule == MicrosoftIdentityModuleType)
{
moduleLoader.AddModule(new MicrosoftIdentityUserAccess.UserAccessModule(configuration));
return;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Administration.Application.Contracts;
using CompanyName.MyMeetings.Modules.Administration.Application.MeetingGroupProposals.AcceptMeetingGroupProposal;
using CompanyName.MyMeetings.Modules.Administration.Application.MeetingGroupProposals.GetMeetingGroupProposal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Meetings.Application.Contracts;
using CompanyName.MyMeetings.Modules.Meetings.Application.Countries;
using Microsoft.AspNetCore.Mvc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Meetings.Application.Contracts;
using CompanyName.MyMeetings.Modules.Meetings.Application.MeetingCommentingConfigurations.DisableMeetingCommentingConfiguration;
using CompanyName.MyMeetings.Modules.Meetings.Application.MeetingCommentingConfigurations.EnableMeetingCommentingConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Meetings.Application.Contracts;
using CompanyName.MyMeetings.Modules.Meetings.Application.MeetingComments.AddMeetingComment;
using CompanyName.MyMeetings.Modules.Meetings.Application.MeetingComments.AddMeetingCommentLike;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Meetings.Application.Contracts;
using CompanyName.MyMeetings.Modules.Meetings.Application.MeetingGroupProposals.GetAllMeetingGroupProposals;
using CompanyName.MyMeetings.Modules.Meetings.Application.MeetingGroupProposals.GetMeetingGroupProposal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Meetings.Application.Contracts;
using CompanyName.MyMeetings.Modules.Meetings.Application.MeetingGroups.EditMeetingGroupGeneralAttributes;
using CompanyName.MyMeetings.Modules.Meetings.Application.MeetingGroups.GetAllMeetingGroups;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Meetings.Application.Contracts;
using CompanyName.MyMeetings.Modules.Meetings.Application.Meetings.AddMeetingAttendee;
using CompanyName.MyMeetings.Modules.Meetings.Application.Meetings.AddMeetingNotAttendee;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Payments.Application.Contracts;
using CompanyName.MyMeetings.Modules.Payments.Application.MeetingFees.CreateMeetingFeePayment;
using CompanyName.MyMeetings.Modules.Payments.Application.MeetingFees.MarkMeetingFeePaymentAsPaid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Payments.Application.Contracts;
using CompanyName.MyMeetings.Modules.Payments.Application.Subscriptions.GetPayerSubscription;
using CompanyName.MyMeetings.Modules.Payments.Application.Subscriptions.GetSubscriptionDetails;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Payments.Application.Contracts;
using CompanyName.MyMeetings.Modules.Payments.Application.PriceListItems.ActivatePriceListItem;
using CompanyName.MyMeetings.Modules.Payments.Application.PriceListItems.ChangePriceListItemAttributes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Payments.Application.Contracts;
using CompanyName.MyMeetings.Modules.Payments.Application.Subscriptions.MarkSubscriptionRenewalPaymentAsPaid;
using Microsoft.AspNetCore.Mvc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Payments.Application.Contracts;
using CompanyName.MyMeetings.Modules.Payments.Application.Subscriptions.MarkSubscriptionPaymentAsPaid;
using Microsoft.AspNetCore.Mvc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Payments.Application.Contracts;
using CompanyName.MyMeetings.Modules.Payments.Application.Subscriptions.BuySubscription;
using CompanyName.MyMeetings.Modules.Payments.Application.Subscriptions.BuySubscriptionRenewal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CompanyName.MyMeetings.API.Modules.UserAccess
namespace CompanyName.MyMeetings.API.Modules.Registrations
{
public class RegisterNewUserRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Autofac;
using CompanyName.MyMeetings.Modules.Registrations.Application.Contracts;
using CompanyName.MyMeetings.Modules.Registrations.Infrastructure;

namespace CompanyName.MyMeetings.API.Modules.Registrations;

internal class RegistrationsAutofacModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<RegistrationsModule>()
.As<IRegistrationsModule>()
.InstancePerLifetimeScope();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using CompanyName.MyMeetings.API.Configuration.Authorization;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.Authorization;
using CompanyName.MyMeetings.Modules.Registrations.Application.Contracts;
using CompanyName.MyMeetings.Modules.Registrations.Application.UserRegistrations.ConfirmUserRegistration;
using CompanyName.MyMeetings.Modules.Registrations.Application.UserRegistrations.RegisterNewUser;
using CompanyName.MyMeetings.Modules.UserAccess.Application.Contracts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace CompanyName.MyMeetings.API.Modules.UserAccess
namespace CompanyName.MyMeetings.API.Modules.Registrations
{
[Route("userAccess/[controller]")]
[ApiController]
Expand Down

This file was deleted.

16 changes: 16 additions & 0 deletions src/API/CompanyName.MyMeetings.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Autofac.Extensions.DependencyInjection;
using Serilog;
using Serilog.Formatting.Compact;

namespace CompanyName.MyMeetings.API
{
Expand All @@ -12,9 +14,23 @@ public static void Main(string[] args)
public static IHostBuilder CreateWebHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.UseSerilog(ConfigureLogger())
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(
webBuilder => { webBuilder.UseStartup<Startup>(); });
}

private static Serilog.ILogger ConfigureLogger()
{
var logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Console(
outputTemplate:
"[{Timestamp:HH:mm:ss} {Level:u3}] [{Module}] [{Context}] {Message:lj}{NewLine}{Exception}")
.WriteTo.File(new CompactJsonFormatter(), "logs/logs")
.CreateLogger();

return logger.ForContext("Module", "Host");
}
}
}
Loading