'Perform auth into another API? Laravel Passport

I have developed an Laravel API which uses oauth 2.0 auth with Passport. Almost all the routes defined in api.php are protected with the middleare auth:api, as is explained in the docs (https://laravel.com/docs/9.x/passport) and everything is working fine.

However, for some reasons, I need to change the API where I make the request related to authentication. Namely, I need that all those protected routes be checked in another API that also has Passport.

Can I perform the middleware check to another API? I know that is possible to change the database in the Passport model but I haven't read anything about requesting to another API.

I also have thought creating a new middleware that makes a specific request to that API (for example, a request that verifies that token contained in headers is valid), but I'm not sure of how to do it and if the method Auth::user (this allows to get the information of logged user) will work.

Does anybody have any suggestion?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source