Skip to content

Add email address to registration and authentication logs#245

Open
phavekes wants to merge 5 commits into
mainfrom
feature/add_more_logging
Open

Add email address to registration and authentication logs#245
phavekes wants to merge 5 commits into
mainfrom
feature/add_more_logging

Conversation

@phavekes

@phavekes phavekes commented Jun 3, 2026

Copy link
Copy Markdown
Member

No description provided.

@phavekes phavekes requested review from kayjoosten and pmeulen June 3, 2026 08:10
{
$this->logger->info('Receiving response from the Azure MFA remote IdP');

$userId = 'unknown';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line entirely. Initializing $userId to a magic string 'unknown' is a code smell it hides whether we actually resolved a real user ID or not. If handleResponse() throws before line 143, we simply don't have a user ID, and the error log should reflect that honestly (see comment on the catch block below) rather than masking it with a sentinel value.

$this->logger->info(sprintf(
'Finishing the registration for user "%s"',
$userId ));
$userId = $this->azureMfaService->finishRegistration($user->getUserId());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$userId is a string (assigned on line 143 via getUserId()->getUserId()), but here it is overwritten with the UserId object returned by finishRegistration(). UserId has no __toString(), so the sprintf calls at lines 164 and 172 will throw a fatal TypeError on every successful registration the SAML response is never sent to the SP.

Fix suggestion: use a separate variable for the return value:

$registeredUserId = $this->azureMfaService->finishRegistration($user->getUserId());
$this->registrationService->register($registeredUserId->getUserId());

$this->authenticationService->authenticate();
}
} catch (Exception $e) {
$this->logger->error(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block still references $userId (line 164), but after the fix on line 151 $userId
can still be undefined here if handleResponse() throws before line 143 ever runs.
Since we genuinely don't know the user at that point, drop it from the error message entirely:

'The authentication or registration failed. Rejecting the Azure MFA response. Error message: "%s"', $e->getMessage()

}

$this->logger->info('Sending a SAML response to the SP');
$this->logger->info(sprintf('Sending a SAML response to the SP for userId "%s"', $userId));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the fix on line 151 (use $registeredUserId instead of reusing $userId), this log line will be correct $userId remains a string for the full method lifetime. No change needed here once the variable reuse on line 151 is fixed.

finishRegistration() returns a UserId object; reusing $userId caused
a TypeError in sprintf on every successful registration. Use a separate
$registeredUserId variable, init $userId as null with ?? fallback,
and drop the unresolvable user from the catch-block error message.
@kayjoosten kayjoosten requested a review from johanib June 4, 2026 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants