@mahmoud-faisal If you don’t want third parties to be able to use your API then you need to add authentication. There’s no magic way to make an API accessible from one source and not another.
Laravel API Protection
I'm trying to make an api using laravel 10 and sanctum
I have for example routes
1-get: articles
2-get: articles/{article}
3-post: articles
4-put: articles/{article}
route 3 and 4 you have to be logged in to be able to access this api so we can use middleware auth:sanctum and all good but the other two routes (1, 2) can be consumed from the front-end without requesting the user to be logged-in so how can I protect these routes so that only my front-end with known domain and my mobile application can access and not any other third party app
isn't there anyway like white listing the domains that can access this type of api?
@Mahmoud-Faisal No. If it’s a public API endpoint, then it’s public. Anything sent in a request (such as Referer/Origin headers) can be easily spoofed by the client.
You can add CORS, but that won’t protect people accessing your API using non-JavaScript approach, such as cURL, Postman, or building a proxy service to scrape your API if it provides access to high-value content worth scraping.
Please or to participate in this conversation.