Jwt-auth: Can't login using Lumen

Created on 10 Apr 2018  路  5Comments  路  Source: tymondesigns/jwt-auth

Subject of the issue

Describe your issue here.

Your environment

| Q | A
| ----------------- | ---
| Bug? | no
| New Feature? | no
| Framework | Lumen
| Framework version | 5.6.*
| Package version | 2.0.x-dev
| PHP version | 7.x.y

Steps to reproduce

tried to use it on Lumen like this
config(['auth.guards.api.driver' => 'jwt' ,'auth.defaults.guard' => 'api' , 'auth.defaults.passwords' => 'users' , 'auth.guards.api.provider' => 'users']);
and all other stuff ,with a Model like this:

class User extends Model implements JWTSubject
{
    /**
     * The users table.
     *
     * @var string
     */
    protected $table = 'users';
    ...
    ...
    ...
    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }
}

Expected behaviour

Attempt to login

Actual behaviour

this error
Type error: Argument 2 passed to Tymon\JWTAuth\JWTGuard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, null given, called in /home/vagrant/sites/Lument/vendor/tymon/jwt-auth/src/Providers/AbstractServiceProvider.php on line 87

Most helpful comment

In config/auth.php does your specified guard provider match one of your declared providers?

So my config is as follows:

``````
'defaults' => [
'guard' => env('AUTH_GUARD', 'api'),
'passwords' => 'users',
],

'guards' => [
    'api' => [
      'driver' => 'jwt',
      'provider' => 'users'
    ],
  ],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model'  =>  App\User::class,
    ]
],

``````

All 5 comments

In config/auth.php does your specified guard provider match one of your declared providers?

So my config is as follows:

``````
'defaults' => [
'guard' => env('AUTH_GUARD', 'api'),
'passwords' => 'users',
],

'guards' => [
    'api' => [
      'driver' => 'jwt',
      'provider' => 'users'
    ],
  ],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model'  =>  App\User::class,
    ]
],

``````

I have faced the same issue and after adding the config/auth.php file it fixed :)

Thanks, my bad

Thank so much, you save my times

In config/auth.php does your specified guard provider match one of your declared providers?

So my config is as follows:

    'defaults' => [
        'guard' => env('AUTH_GUARD', 'api'),
        'passwords' => 'users',
    ],

    'guards' => [
        'api' => [
          'driver' => 'jwt',
          'provider' => 'users'
        ],
      ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model'  =>  App\User::class,
        ]
    ],

Thanks man 馃憣

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gandra picture gandra  路  3Comments

therealmjk picture therealmjk  路  3Comments

mihailo-misic picture mihailo-misic  路  3Comments

Rasoul-Karimi picture Rasoul-Karimi  路  3Comments

harveyslash picture harveyslash  路  3Comments