Search code examples
laravelapioauthoauth-2.0laravel-passport

How to restrict access in Passport Client Credentials grant type when we have multiple clients


I want to provide API for two banks (machine to machine). AFAIK the best grant type for this purpose is Client Credentials. But how can I restrict bank A to access only ControllerA and bank B to access only ControllerB?

it doesn't seem right to create two user for these banks!


Solution

  • You can use middleware (https://laravel.com/docs/5.7/middleware#assigning-middleware-to-routes) like the ‘checkRole’ example and optionally, use token scopes (https://laravel.com/docs/5.6/passport#token-scopes), to protect your routes.