Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sentiemce's avatar

Protect API calls

Im fairly new to laravel and I'm hoping someone could push me in the right direction. I have a Javascript frontend, its views are not served by laravel but it makes calls to a laravel API. All i have for authentication is an external api where user login credentials are sent and if they are correct a username is returned.

If username is returned then a new user through model is created in laravel backend. At the moment there is nothing stoping from someone to say that the first authentication api returned a different username and submitting that to the laravel api. I Think that the first auth api should return some sort of random token that that will be saved to the laravel user so you cant just submit the user name that other people might know.

Should i use laravel passport for this?

0 likes
2 replies
martinbean's avatar

@sentiemce Yes, you should be using some form of token-based authentication instead of just returning a username. As you’ve identified, if someone is able to get the username of a valid user then they’re going to be able to make API requests, which isn’t secure at all.

Passport is an OAuth server implementation so will add OAuth-based authentication to your application. Sanctum is a simpler solution for adding API token-based authentication to your applications.

Please or to participate in this conversation.