Passport: Always response 401 (Unauthorized) for my Laravel Passport generated OAuth 2 token

Created on 12 Feb 2018  Â·  6Comments  Â·  Source: laravel/passport

I am using:

Postman/Insomnia for REST checking
Laravel 5.6 with Laravel Passport
Vagrant (Apache 2, PHP 7.2)
Made all checklist described on Laravel Docs for Laravel Passport and after certain steps I receive HTTP 401 for my valid OAuth access token.

Requested by /oauth/token/ the new access token with client_id and client_secret.
Used received access token to authorize my simple Laravel REST test controller with included Oauth api middleware.
The end is one: 401 unauthorized :(
So, here is some of my configurations:

Apache
image

api route
image

Kernel.php
image

PassportServiceProvider.php
image

AuthServiceProvider.php
image

Most helpful comment

As I stated above, we need to see the request you are making to obtain a token.

This is not a forum for “how to use passport” it’s for issue tracking. Logging an issue on an issue tracker you do the following:

  • List the versions of packages
  • give a replicatable scenario and even better a git repo with a replicatable issue
  • example requests of your entire auth workflow

Questions like you posed “why do I get 401, here are Some code screenshots” is basically asking us to do your work for you. We are not your co-workers. Stackoverflow is used for these userland issues.

But since you asked:

Clear your cache, clear your config, clear the database, reinstall.

All 6 comments

Can you post the request you are issuing to obtain your token, im sure that is where your issue is. You can t use a token that is issued incorrectly.

@andrewmclagan I am getting this issue with Laravel 5.6 now as well. I have had it since Laravel 5.3 where I can get the token just fine, but trying to use the token to access a link that uses auth:api always returns 401 unathenticated. I always resort to using another package as I have tried everything suggested online and nothing ever works for me to solve the problem.

As I stated above, we need to see the request you are making to obtain a token.

This is not a forum for “how to use passport” it’s for issue tracking. Logging an issue on an issue tracker you do the following:

  • List the versions of packages
  • give a replicatable scenario and even better a git repo with a replicatable issue
  • example requests of your entire auth workflow

Questions like you posed “why do I get 401, here are Some code screenshots” is basically asking us to do your work for you. We are not your co-workers. Stackoverflow is used for these userland issues.

But since you asked:

Clear your cache, clear your config, clear the database, reinstall.

Okay, the problem was solved.
Do not now what exactly that was but when I set up laravel passport vue components to manage clietns and used in Insomnia authorize url (/oauth/authorize) all is okay.
Earlier I didn't used authorize route, just Client Creditinails as I see. Also I edited some config files in Kernel to use to use client_credentials.

I forgot to include the auth:api middleware on the routes that need api-authentication, causing this issue

image
I am facing this error while login with social media

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Patskimoto picture Patskimoto  Â·  3Comments

mehrancodes picture mehrancodes  Â·  3Comments

mind-control picture mind-control  Â·  3Comments

brryfrmnn picture brryfrmnn  Â·  3Comments

duccanh0022 picture duccanh0022  Â·  3Comments