mohit
mohit

Reputation: 290

Laravel 5.5 api authorization with API Token

I am trying to authenticate our user using the API token,

Here is my code config/auth.php code

  'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],

My Api.php is like this

Route::group(['middleware' => ['subdomain_setup','auth::api'],'prefix'=>'v1'], function () {
    Route::get('getCoupons','Api\CouponAPI@getCoupons');
});

Now I am getting this error while accessing my api URL

Column not found: 1054 Unknown column 'api_token' in 'where clause' (SQL: select * from users where api_token =

Upvotes: 5

Views: 11736

Answers (3)

Mr.Senhaji
Mr.Senhaji

Reputation: 450

Clear the cache :

Clear Application Cache Run the following command to clear application cache of the Laravel application.

php artisan cache:clear

Clear config cache You can use config:clear to clear the config cache of the Laravel application.

php artisan config:clear

Upvotes: 1

Sahak Hakobyan
Sahak Hakobyan

Reputation: 146

Make sure you have run Passport migration and ['guards']['api']['driver'] set to passport in config/auth.php, and updated the configuration cache

'guards' => [
    'web' => [
        'driver' => 'session', 
        'provider' => 'users', 
    ], 

    'api' => [ 
        'driver' => 'passport', 
        'provider' => 'users', 
    ], 
],

Upvotes: 14

huangfu
huangfu

Reputation: 37

You must alter table to add a 'api_token' field.

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');

    //Add api_token field
    $table->string('api_token', 60)->unique();

    $table->rememberToken();
    $table->timestamps();
});

Upvotes: 2

Related Questions