Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.3 Personal access token 500

I'm trying to set up my custom API with Passport (well, I'm already halfway through, just need to build my authentication). Whenever I'm trying to create a personal access token from my Passport dashboard (/home route), I get a 'Whoops, something went wrong!' error.

This comes from my Vue component (PersonalAccessTokens.vue), and my console logs me a 500 internal server error at the Post route for storing personal access tokens...

\Laravel\Passport\Http\Controllers\PersonalAccessTokenController@store is the method responsible but I can't seem to find something outof the ordinary as I did exactly follow the Laracasts video about Passport

Anyone else experiencing this problem ?

TIA!

like image 874
Fabian Tjoe A On Avatar asked Nov 12 '16 13:11

Fabian Tjoe A On


People also ask

How can I get laravel personal access token?

To generate an access token for a single user, I am using below code to generate a token with name 'android'. $user = User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), ]); // Here the access token will be stored in $token variable.

How long is a personal access token?

Custom API token lifetime By default, an access token for a custom API is valid for 86400 seconds (24 hours). We recommend that you set the validity period of your token based on the security requirements of your API.

How do I enable my personal access token?

From your home page, open user settings and select Personal access tokens. Select + New Token. Name your token, select the organization where you want to use the token, and then set your token to automatically expire after a set number of days. Select the scopes for this token to authorize for your specific tasks.

Is laravel Passport stateless?

Laravel Passport is an OAuth 2.0 server implementation for stateless authentication.


2 Answers

I figured it out.

Apparently it can't read my personal access token client, that you should generate when setting up Passport by using the command: php artisan passport:install

Running this command solves my problem.

Reference: https://laracasts.com/discuss/channels/laravel/create-personal-access-token-in-laravel-passport-is-failing

like image 162
Fabian Tjoe A On Avatar answered Oct 02 '22 09:10

Fabian Tjoe A On


A little more info on this as I've been having the same problem. You need to run:

php artisan passport:install

each time you refresh your migrations by doing:

php artisan migrate:refresh

To deal with this I've just added a script to package.json which uses npm-run-all so I can do it in one command:

"scripts": {
  // Other scripts
  "migrate:refresh": "php artisan migrate:refresh",
  "passport:install": "php artisan passport:install",
  "db:refresh": "npm-run-all --sequential migrate:refresh passport:install"
}

Now I can just do:

npm run db:refresh

like image 39
craig_h Avatar answered Oct 02 '22 10:10

craig_h