Jwt-auth: Auth guard driver [api] is not defined

Created on 23 Dec 2016  路  7Comments  路  Source: tymondesigns/jwt-auth

Hi guys! I have a problem utilizing laravel 5.3 and jwt-auth:0.5.9. I used it until I needed to update the expired token and since then it no longer met my expectations, and now returned Unauthenticated for validate authenticate.

I'm using a guard for each type of connection to api. Be it facebook, form, twitter, among others. This was the way I found to perform the verification in separate cases, both in the application and in the database.

InvalidArgumentException in AuthManager.php line 99:
Auth guard driver [api] is not defined.

  • Obs.: The guide #860 doesn't meet what I need.

auth.php file:

'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],
'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

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

        'formAuth' => [
            'driver' => 'jwt',
            'provider' => 'formAuth'
        ],
    ],

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

        'formAuth' => [
            'driver' => 'eloquent',
            'model' => App\Models\Auth\FormAuth::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

LoginController::login() controller:

public function login(Request $request)
    {
        $authManager = new AuthManager($request, HttpManager::getAuthType($request));

        $this->validateLogin($request);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        $credentials = $this->credentials($request);

        if ($token = $authManager->getStaticGuard()->attempt($credentials)) {
            return $this->sendLoginResponse($request, $authManager, $token);
        }
...

AuthManager file:

...
/**
     * @return Factory|Guard|StatefulGuard
     */
    public function getStaticGuard()
    {
        return auth();
    }

    /**
     * Set the guarded attributes for the model.
     *
     * @return Factory|Guard|StatefulGuard
     */
    public function getGuard()
    {
        return auth($this->getUserRelation());
    }
...

All 7 comments

I solved my problem with two old Middlewares from 0.5.x version.

how you have solved the problem because i have the same and i don't know how solve it

How you solved your problem? Remove the two middlewares?

The guard informed in guards array needs to exist in providers array also.
In my case, I used the formAuth guard that implemented with FormAuth model.

@francisrod01 Can you elaborate? How did you change your code from the code you posted initially?

did you solve it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rasoul-Karimi picture Rasoul-Karimi  路  3Comments

harveyslash picture harveyslash  路  3Comments

aofdev picture aofdev  路  3Comments

johncloud200 picture johncloud200  路  3Comments

loic-lopez picture loic-lopez  路  3Comments