Amitoz Deol
Amitoz Deol

Reputation: 442

Laravel passport oauth/tokens GET API not working

I just installed Passport and added Passport::routes() to my serviceprovider. It gave me these routes /oauth/token POST, /oauth/tokens GET, /oauth/token/{Token_id} DELETE. I am using Password Grant Tokens for authentication(https://laravel.com/docs/5.6/passport#password-grant-tokens)

I ran the POST request to make a new token and it created the token just fine. But when I try to run the GET to see all the token, it returns an empty array. I have around 10 tokens already generated in my DB.

Shouldn't I be getting a list of all the oauth tokens that's stored in the database?
If not, Is there a way to index all the tokens for admin use?

Upvotes: 0

Views: 2020

Answers (1)

Alec Joy
Alec Joy

Reputation: 1989

The GET /oauth/tokens route returns all tokens for the currently authenticated user only, not all users.

To get all tokens, with their associated users, you can use the following.

\Laravel\Passport\Token::with('user')->get()

Upvotes: 1

Related Questions