Skip to content

auth-oauth2: log callback failures to system logs#304

Open
pmdrs wants to merge 1 commit into
osTicket:developfrom
pmdrs:log-oauth2-callback-errors
Open

auth-oauth2: log callback failures to system logs#304
pmdrs wants to merge 1 commit into
osTicket:developfrom
pmdrs:log-oauth2-callback-errors

Conversation

@pmdrs

@pmdrs pmdrs commented Jun 23, 2026

Copy link
Copy Markdown

Summary

OAuth2AuthenticationTrait::callback() has a //TODO: Log any errors to system logs comment that was never implemented, paired with a bare catch (Exception $ex) { return false; }. Every authentication failure in the OAuth2 callback flow — staff, end-user, and email-account variants all share this trait — is currently invisible to admins: nothing is written to the System Logs (ost_syslog), and the user/agent is just silently bounced back to the login screen.

This PR adds $ost->logWarning()/logError() calls on each failure branch. No behavior changes — return values are identical; this only adds diagnostics.

Reproduction (currently silent)

  1. Configure an OAuth2 IdP with an intentionally wrong client secret (or wait for a token to expire).
  2. Attempt to sign in via OAuth2 as a staff or end user.
  3. The IdP token exchange fails (e.g. invalid_client/invalid_grant), the catch (Exception $ex) swallows it, and the user is redirected back to login with no message.
  4. Check Admin Panel → System Logs: nothing is recorded. There is no way for an admin to diagnose why authentication is failing.

A second silent path: the token exchange succeeds but signIn() can't match/auto-register the returned attributes to a local account (e.g. missing username/email claim from the IdP) — also currently unlogged.

Test plan

  • Configure OAuth2 with a bad client secret; confirm a logWarning/logError entry now appears in System Logs on failed callback.
  • Successful login flow is unaffected (no new log entries, same redirect behavior).
  • Confirm staff, end-user, and email-account OAuth2 backends (which all use OAuth2AuthenticationTrait) still authenticate correctly.

OAuth2AuthenticationTrait::callback() had a TODO comment and a bare
catch (Exception $ex) { return false; } that silently swallowed all
authentication errors. Admins had zero visibility when an IdP returned
invalid_client/invalid_grant, when the OAuth2 state did not match, or
when sign-in/auto-registration failed after a successful token
exchange.

Add $ost->logWarning()/logError() calls on each failure path. No
behavior change - the method still returns the same values; it now
also records a diagnostic entry in the System Logs (ost_syslog).
@pmdrs pmdrs force-pushed the log-oauth2-callback-errors branch from 1802fda to 0e8b04d Compare June 23, 2026 11:15
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.

1 participant