Integrate 2FA with Twilio in Laravel [closed]

I have a PHP Laravel backend application that uses the Passport package for authentication. I want to integrate Two-Factor Authentication (2FA) using Twilio into the login flow.

The issue I’m facing is that the /oauth/token API in Laravel Passport automatically creates an access token and authenticates the user as soon as valid credentials are provided. Because of this, there’s no opportunity to introduce a 2FA step before the token is issued.

My goal is to:

  1. Validate the user’s credentials (email and password).
  2. If 2FA is enabled for the user, send a verification code via Twilio and require the user to verify it.
  3. Issue the access token only after the 2FA verification is successfully completed.

How can I modify or extend the Passport authentication flow to achieve this? Any guidance or examples would be greatly appreciated!