Skip to content

Commit

Permalink
#VP-6504 add user login event publish (VirtoCommerce#2140)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev authored Feb 1, 2021
1 parent dea13c8 commit f1624ef
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
using OpenIddict.Core;
using OpenIddict.EntityFrameworkCore.Models;
using VirtoCommerce.Platform.Core;
using VirtoCommerce.Platform.Core.Events;
using VirtoCommerce.Platform.Core.Security;
using VirtoCommerce.Platform.Core.Security.Events;

namespace Mvc.Server
{
Expand All @@ -27,21 +29,24 @@ public class AuthorizationController : Controller
private readonly UserManager<ApplicationUser> _userManager;
private readonly IUserClaimsPrincipalFactory<ApplicationUser> _userClaimsPrincipalFactory;
private readonly AuthorizationOptions _authorizationOptions;
private readonly IEventPublisher _eventPublisher;

public AuthorizationController(
OpenIddictApplicationManager<OpenIddictApplication> applicationManager,
IOptions<IdentityOptions> identityOptions,
SignInManager<ApplicationUser> signInManager,
UserManager<ApplicationUser> userManager,
IUserClaimsPrincipalFactory<ApplicationUser> userClaimsPrincipalFactory,
IOptions<AuthorizationOptions> authorizationOptions)
IOptions<AuthorizationOptions> authorizationOptions,
IEventPublisher eventPublisher)
{
_applicationManager = applicationManager;
_identityOptions = identityOptions;
_signInManager = signInManager;
_userManager = userManager;
_userClaimsPrincipalFactory = userClaimsPrincipalFactory;
_authorizationOptions = authorizationOptions.Value;
_eventPublisher = eventPublisher;
}

#region Password, authorization code and refresh token flows
Expand Down Expand Up @@ -108,6 +113,8 @@ public async Task<ActionResult> Exchange(OpenIdConnectRequest openIdConnectReque
await HttpContext.SignInAsync(IdentityConstants.ApplicationScheme, claimsPrincipal);
}

await _eventPublisher.Publish(new UserLoginEvent(user));

return SignIn(ticket.Principal, ticket.Properties, ticket.AuthenticationScheme);
}
else if (openIdConnectRequest.IsAuthorizationCodeGrantType() || openIdConnectRequest.IsRefreshTokenGrantType())
Expand Down

0 comments on commit f1624ef

Please sign in to comment.