I have the exact same issue myself right now when trying to setup an OAuth API with Laravel Passport. I login to my app with user email and password and then accept the OAuth scope request to get my token. At this stage, using the generated token to access my test /api/user route returns {"error":"Unauthenticated."}
@znittzel did you ever find a solution?
I had this issue as well. Seems like the expiration time for the token was being set to a negative value by default. I added the following lines to the boot method in my AuthServiceProvider and it fixed the issue for me:
Passport::tokensExpireIn(Carbon::now()->addDays(7));
Passport::refreshTokensExpireIn(Carbon::now()->addDays(14));
Try by sending 'Accept: application/json' along with 'Authorization: Bearer {acces_token}' in the header of POST REQUEST to /api/user. It worked for me. I didn't need to set special expiration date on token.
Are you using the Authorization
header with the Bearer YOUR-AUTH-TOKEN
value?
Do you have any scopes applied to your routes that you haven't explicitly granted to your token?
@balakan is right
Put the header in the following way:
Accept:application/json,
Authorization:Bearer xxx
where xxx is your access token.
@Tyler is right for me too.
library:
laravel/framework versions : * v5.3.22
laravel/passport versions : * v1.0.10
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community