I hope someone could explain why I'm unauthenticated
when already has performed a successfull Oauth 2
authentication process.
I've set up the Passport
package like in Laravel's documentation and I successfully get authenticated, receives a token value and so on. But, when I try to do a get
request on, let say, /api/user
, I get a Unauthenticated
error as a response. I use the token value as a header with key name Authorization
, just as described in the docs.
Route::get('/user', function (Request $request) {
return $request->user();
})->middleware("auth:api");
This function is suppose to give back my self as the authenticated user, but I'm only getting Unauthenticated
. Likewise, if I just return the first user, I'm again getting Unauthenticated
.
Route::get('/test', function(Request $request) {
return App\User::whereId(1)->first();
})->middleware("auth:api");
In a tutorial from Laracast
, guiding through the setup of Passport
, the guider doesn't have the ->middleware("auth:api")
in his routes. But if its not there, well then there's no need for authentication at all!
Please, any suggestions or answers are more then welcome!
routes
that you write inside yourroutes\api.php
file are by default protected with the api middleware. So, you can remove your explicit mentioning of->middleware("auth:api")
. – Hari Harker