Chris
Chris

Reputation: 4386

Laravel Passport: use api guard for passport specific routes

I'm writing a REST API using laravel (5.6) and passport. In the documentation it says that it's possible to use the json api for making passport specific requests (for example to get tokens, create or edit clients etc). (https://laravel.com/docs/5.6/passport#managing-clients)

However when I want to use these passport routes in my angular frontend using the REST interface, y get "Unauthenticated" errors, also while using the correct access token.

I searched the passport classes (mainly RouteRegistrar) and found that they always use the web guard. How to solve this?

I searched if it's possible to configure the Passport::routes() in some way but did not find anything in the docs. So is the only solution not using the Passport::routes(); and writing custom routes with auth:api middleware instead of auth:web?

Upvotes: 1

Views: 957

Answers (1)

Chris
Chris

Reputation: 4386

Ok, I found something:

In the AuthServiceProvider under boot, put

Passport::routes(null,array('middleware'=> 'auth:api'));

instead of only

 Passport::routes()

This merges the middleware as options. I leave it here in case someone else runs into this issue.

Upvotes: 2

Related Questions