Support the ongoing development of Laravel.io →
API Authentication Sanctum

the problem I want to solve is to protect an API route so only allowed servers with a token can access it.

I added the Sanctum package and included the auth:sanctum middleware in the route definition. That route is entered even when the request includes an invalid token.

How to make the middleware stop processing when the token is invalid and send a HTTP 401 response.

The Laravel application only provides an API, no frontend. It's only used by other servers we controlss, not from browsers.

amethgaye, justany liked this thread

2

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.