user908759
user908759

Reputation: 1355

Laravel 5.4 Passport Personal Token Postman Error Unauthenticated

I am using Laravel 5.4 Passport for personal tokens. I am trying to use Postman to send a GET request to /api/user. I get my token by sending a GET request to /oauth/personal-access-tokens. From that response I grab what I think is the token then I set up a GET request in Postman like the documents say Adding Accept => application/json and Authorization => Bearer token. Below is an example:

After logging in, I go to http://192.168.10.15/oauth/personal-access-tokens in my browser I see the following:

[
  {
    "id": "96a494affb39097a562e12e53a32c028cb9b9b481ba4e92ca9fa35df6361583ff9bf3422268345aa",
    "user_id": 1,
    "client_id": 1,
    "name": "API-Token",
    "scopes": [

    ],
    "revoked": false,
    "created_at": "2018-04-28 14:50:02",
    "updated_at": "2018-04-28 14:50:02",
    "expires_at": "2019-04-28 14:50:02",
    "client": {
      "id": 1,
      "user_id": null,
      "name": "Test Site Personal Access Client",
      "redirect": "http:\/\/localhost",
      "personal_access_client": true,
      "password_client": false,
      "revoked": false,
      "created_at": "2018-04-28 14:49:18",
      "updated_at": "2018-04-28 14:49:18"
    }
  }
]

I'm guessing the token is the id?!?!? It seems pretty short.

Here is my api.php file:

Route::get('/user', function (Request $request) {
    return $request->user();
})->middleware('auth:api');

I then copy the token from /oauth/personal-access-tokens and use it in my Postman Get request to http://192.168.10.15/api/user below:

enter image description here

enter image description here

Am I actually getting the token with the /oauth/personal-access-tokens GET request? and if I am why and I getting the Unauthenticated error?

I have already checked here done the following in AuthServiceProvider.php boot():

Passport::routes();

Passport::tokensExpireIn(Carbon::now()->addYears(20));
Passport::refreshTokensExpireIn(Carbon::now()->addYears(20));
Passport::pruneRevokedTokens();

I am also set up to Consume My API with Javascript

I appreciate any and all help! Please let me know if any other information is need to diagnose this problem.

Upvotes: 0

Views: 1325

Answers (1)

HG Sim
HG Sim

Reputation: 136

The "id" is not the the token. To create a valid bearer token, you can refer Laravel doc

Upvotes: 3

Related Questions