Skip to content

Commit

Permalink
add Configuration infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEggenberger committed Nov 24, 2024
1 parent 33c9b80 commit c006fb7
Show file tree
Hide file tree
Showing 20 changed files with 336 additions and 356 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,16 @@
using Modules.Channels.Features.DomainFeatures.Channels.Application.Queries;
using Shared.Kernel.BuildingBlocks.Authorization.Attributes;
using Modules.Channels.Web.Shared.DTOs.ChannelAggregate;
using Shared.Features.Server;

namespace Modules.Channels.Web.Server.Controllers
{
[Route("api/[controller]")]
[ApiController]
[ApiVersion("1.0")]
public class ChannelsController : ControllerBase
[Authorize]
public class ChannelsController : BaseController
{
private readonly IMapper mapper;
private readonly ICommandDispatcher commandDispatcher;
private readonly IQueryDispatcher queryDispatcher;
private readonly IAuthorizationService authorizationService;

public ChannelsController(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher, IMapper mapper, IAuthorizationService authorizationService)
{
this.commandDispatcher = commandDispatcher;
this.queryDispatcher = queryDispatcher;
this.mapper = mapper;
this.authorizationService = authorizationService;
}
public ChannelsController(IServiceProvider serviceProvider) : base(serviceProvider) { }

[HttpGet]
public async Task<List<ChannelDTO>> GetChannels(CancellationToken cancellationToken)
Expand Down Expand Up @@ -87,15 +77,7 @@ public async Task UpdateChannel([FromBody] ChannelDTO updateChannelDTO, Cancella
public async Task<ActionResult> DeleteChannel([FromRoute] Guid id, CancellationToken cancellationToken)
{
Channel channel = await queryDispatcher.DispatchAsync<GetChannelById, Channel>(new GetChannelById { Id = id }, cancellationToken);
if ((await authorizationService.AuthorizeAsync(HttpContext.User, channel, "CreatorPolicy")).Succeeded)
{
await commandDispatcher.DispatchAsync(new DeleteChannel() { ChannelId = id }, cancellationToken);
return Ok();
}
else
{
return Forbid();
}

}
}
}

This file was deleted.

69 changes: 69 additions & 0 deletions Source/Modules/Subscriptions/Web/Server/WebHooks/StripeWebhook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Shared.Modules.Layers.Application.Messaging.Command;
using Shared.Modules.Layers.Features.StripeIntegration;
using Shared.Modules.Layers.Features.StripeIntegration.Commands;
using Shared.Modules.Layers.Features.StripeIntegration.Configuration;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Stripe;
using System.IO;
using Shared.Features.Server;

namespace Web.Server.Controllers.Stripe
{
[Route("api/[controller]")]
[ApiController]
public class StripeWebhook : BaseController
{
private readonly StripeOptions stripeOptions;
private readonly ICommandDispatcher commandDispatcher;
public StripeWebhook(IOptions<StripeOptions> stripeOptions, ICommandDispatcher commandDispatcher)
{
this.stripeOptions = stripeOptions.Value;
this.commandDispatcher = commandDispatcher;
}

[HttpPost]
[IgnoreAntiforgeryToken]
[AllowAnonymous]
public async Task<IActionResult> Index()
{
var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();
try
{
var stripeEvent = EventUtility.ParseEvent(json);
var signatureHeader = Request.Headers["Stripe-Signature"];
stripeEvent = EventUtility.ConstructEvent(json,
signatureHeader, stripeOptions.EndpointSecret);

//More Events Events.Checkout...
if (stripeEvent.Type == Events.CustomerSubscriptionCreated)
{
var subscription = stripeEvent.Data.Object as Subscription;
await commandDispatcher.DispatchAsync(new CreateSubscriptionCommand { Subscription = subscription });
}
else if (stripeEvent.Type == Events.CustomerSubscriptionUpdated)
{
var subscription = stripeEvent.Data.Object as Subscription;
await commandDispatcher.DispatchAsync(new UpdateSubscriptionCommand { Subscription = subscription });
}
else if (stripeEvent.Type == Events.CustomerSubscriptionDeleted)
{
var subscription = stripeEvent.Data.Object as Subscription;
await commandDispatcher.DispatchAsync(new DeleteSubscriptionCommand { Subscription = subscription });
}
else if (stripeEvent.Type == Events.CustomerSubscriptionTrialWillEnd)
{
var subscription = stripeEvent.Data.Object as Subscription;
await commandDispatcher.DispatchAsync(new SubscriptionTrialEndedCommand { Subscription = subscription });
}
return Ok();
}
catch (StripeException e)
{
throw new StripeIntegrationException(e.Message);
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Shared.Kernel.BuildingBlocks.Auth.Constants;
using Modules.TenantIdentity.Features.DomainFeatures.Users;
using Shared.Kernel.Extensions.ClaimsPrincipal;
using Modules.TenantIdentity.Features.DomainFeatures.Users.Application.Commands;
using Shared.Features.Server;
using System;
using System.Threading.Tasks;
using Modules.TenantIdentity.Features.DomainFeatures.Users;
using Modules.TenantIdentity.Features.DomainFeatures.Users.Application.Commands;

namespace Modules.TenantIdentity.Web.Server
namespace Modules.TenantIdentity.Web.Server.Controllers.IdentityOperations
{
[Route("api/[controller]")]
[AllowAnonymous]
Expand All @@ -16,8 +18,7 @@ public class ExternalLoginCallbackController : BaseController
{
private readonly SignInManager<ApplicationUser> signInManager;
private readonly UserManager<ApplicationUser> userManager;

public ExternalLoginCallbackController(SignInManager<ApplicationUser> signInManager, UserManager<ApplicationUser> userManager, IServiceProvider services) : base(services)
public ExternalLoginCallbackController(SignInManager<ApplicationUser> signInManager, UserManager<ApplicationUser> userManager, IServiceProvider serviceProvider) : base(serviceProvider)
{
this.signInManager = signInManager;
this.userManager = userManager;
Expand All @@ -27,6 +28,7 @@ public ExternalLoginCallbackController(SignInManager<ApplicationUser> signInMana
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null)
{
var info = await signInManager.GetExternalLoginInfoAsync();

var user = await userManager.FindByLoginAsync(info.LoginProvider, info.ProviderKey);

if (info is not null && user is null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Modules.TenantIdentity.Features.DomainFeatures.Tenants.Application.Queries;
using Modules.TenantIdentity.Features.DomainFeatures.Users;
using Modules.TenantIdentity.Features.DomainFeatures.Users.Application.Commands;
using Modules.TenantIdentity.Features.DomainFeatures.Users.Application.Queries;
using Modules.TenantIdentity.Shared.DTOs.IdentityOperations;
using Shared.Features.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Modules.TenantIdentity.Shared.DTOs.Tenant;
using Modules.IdentityModule.Shared;

namespace Modules.TenantIdentity.Web.Server.Controllers.IdentityOperations
{
[Route("api/[controller]")]
[Authorize]
[ApiController]
public class IdentityOperationsController : BaseController
{
private readonly SignInManager<ApplicationUser> signInManager;

public IdentityOperationsController(SignInManager<ApplicationUser> signInManager, IServiceProvider serviceProvider) : base(serviceProvider)
{
this.signInManager = signInManager;
}

[HttpGet]
[AllowAnonymous]
public ActionResult<BFFUserInfoDTO> GetClaimsOfCurrentUser()
{
if (!User.Identity.IsAuthenticated)
{
return BFFUserInfoDTO.Anonymous;
}
return new BFFUserInfoDTO()
{
Claims = User.Claims.Select(claim => new ClaimValueDTO { Type = claim.Type, Value = claim.Value }).ToList()
};
}

[HttpGet("selectTenant/{TenantId}")]
public async Task<ActionResult> SetTenantForCurrentUser(Guid tenantId, [FromQuery] string redirectUri)
{
var user = await queryDispatcher.DispatchAsync<GetUserById, ApplicationUser>(new GetUserById { });

var tenantMembershipsOfUserQuery = new GetAllTenantMembershipsOfUser() { UserId = user.Id };
var tenantMemberships = await queryDispatcher.DispatchAsync<GetAllTenantMembershipsOfUser, List<TenantMembershipDTO>>(tenantMembershipsOfUserQuery);

if (tenantMemberships.Select(t => t.TenantId).Contains(tenantId))
{
var setSelectedTenantForUser = new SetSelectedTenantForUser { };
await commandDispatcher.DispatchAsync(setSelectedTenantForUser);
await signInManager.RefreshSignInAsync(user);
}
else
{
throw new Exception();
}

return LocalRedirect(redirectUri ?? "/");
}

[HttpGet("Logout")]
public async Task<ActionResult> LogoutCurrentUser([FromQuery] string redirectUri)
{
await signInManager.SignOutAsync();
return LocalRedirect(redirectUri ?? "/");
}
}
}
Loading

0 comments on commit c006fb7

Please sign in to comment.