Skip to content

Commit

Permalink
Make Laravel appsec login success event more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
estringana committed Mar 28, 2024
1 parent 3d4313f commit fc98f13
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Integrations/Integrations/Laravel/LaravelIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,27 +357,27 @@ function ($This, $scope, $args, $loginSuccess) use ($integration) {

// Used by Laravel >= 5.0
\DDTrace\hook_method(
'Illuminate\Auth\SessionGuard',
'setUser',
'Illuminate\Auth\Events\Authenticated',
'__construct',
function ($This, $scope, $args) use ($integration) {
$authClass = 'Illuminate\Contracts\Auth\Authenticatable';
if (
!function_exists('\datadog\appsec\track_user_login_success_event') ||
!isset($args[0]) ||
!$args[0] ||
!($args[0] instanceof $authClass)
!isset($args[1]) ||
!$args[1] ||
!($args[1] instanceof $authClass)
) {
return;
}
$metadata = [];
if (isset($args[0]['name'])) {
$metadata['name'] = $args[0]['name'];
if (isset($args[1]['name'])) {
$metadata['name'] = $args[1]['name'];
}
if (isset($args[0]['email'])) {
$metadata['email'] = $args[0]['email'];
if (isset($args[1]['email'])) {
$metadata['email'] = $args[1]['email'];
}
\datadog\appsec\track_user_login_success_event(
\method_exists($args[0], 'getAuthIdentifier') ? $args[0]->getAuthIdentifier() : '',
\method_exists($args[1], 'getAuthIdentifier') ? $args[1]->getAuthIdentifier() : '',
$metadata,
true
);
Expand All @@ -387,7 +387,7 @@ function ($This, $scope, $args) use ($integration) {
// Used by Laravel < 5.0
\DDTrace\hook_method(
'Illuminate\Auth\Guard',
'setUser',
'login',
function ($This, $scope, $args) use ($integration) {
$authClass = 'Illuminate\Auth\UserInterface';
if (
Expand Down

0 comments on commit fc98f13

Please sign in to comment.