I was kind of surprised that I did not find any practical examples or best practices concerning two-factor authentication for laravel using passport.
As I would like to implement this step while a user logs in to the API and receives his access token I am not quiet sure how to approach in a secure manner.
The current process is as follows:
- User sees frontend login page (vue SPA).
- User enters
usernameandpasswordand hits submit. - SPA sends request to API.
- API responds with access token or gives a not authenticated error if something was wrong.
- SPA can use access token to request other resources from API till token is invalidated.
As I would like to enable users to activate or deactivate 2FA individually (because some clients might not want to use it, some will), I would add a new column in my users table to store if 2FA is enabled or not.
But how to continue then? Should the user authenticate with username and password regularly as before, then API knows if he "needs" the second auth step and returns a flag so frontend knows to display another view to enter the token?
Thankful for any input :)