Support the ongoing development of Laravel.io →
Authentication Security
Last updated 2 years ago.
0

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?

Last updated 8 years ago.
0

i also have the same problem.. anyone have a solution?

0

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));

Last updated 8 years ago.
0

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.

0

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?

0

@balakan is right

Put the header in the following way:

Accept:application/json,
Authorization:Bearer xxx

where xxx is your access token.

0

@Tyler is right for me too.

library:

laravel/framework versions : * v5.3.22

laravel/passport versions : * v1.0.10

0

Sign in to participate in this thread!

Eventy

Your banner here too?

znittzel znittzel Joined 24 Oct 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.