0
votes


I've upgraded my project on Laravel 5.2 to Laravel 5.3 to use Laravel passport for api routes.
After couple of weeks I still can't get tokens to work, I always get an unauthenticated error.
After all investigations I've started debugging Laravel Passport and understand that my problem is here (\vendor\lcobucci\jwt\src\Parser.php):

 protected function splitJwt($jwt)
    {
        if (!is_string($jwt)) {
            throw new InvalidArgumentException('The JWT string must have two dots');
        }

        $data = explode('.', $jwt);

        if (count($data) != 3) {
            throw new InvalidArgumentException('The JWT string must have two dots');
        }

        return $data;
    }

Tokens that I get from

$this->user->createToken($this->user->id.' Access Token')->accessToken;

Just have no dots, so can't be exploded. I don't know why, but think that it is the main question.
Typical token that I get looks like this one: 1369781b342d5181072c7f2859a54102f1dc992f6367c4b8ac37193799ec893438ad1b6ac43af3ae

Can somebody help me with this problem?
Thanks in advance

1
In laravel 5.3 for API authentication it uses OAUTH by default .. Its not using JWT. For JWT you have to update auth guard. Have you configured something with guard ? - Suresh Velusamy
Yes, I've used this instruction laravel.com/docs/5.3/passport. My config/auth.php have this 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'passport', 'provider' => 'users', ], ],'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'passport', 'provider' => 'users', ], ],` - Вася Аристов
So you are not using JWT as your auth guard. You need to configure JWT supported auth guard to make your api's are authenticated by JWT. You may use the following package to achieve your need https://github.com/irazasyed/jwt-auth-guard - Suresh Velusamy
Sorry, but the whole task is to use Laravel Passport. Jwt appears here because composer.json of laravel/passport uses it prntscr.com/f8uryg . And I cannot modify vendor files - Вася Аристов
Take a look on this thread .. it will clarify . https://github.com/laravel/passport/issues/222 - Suresh Velusamy

1 Answers

2
votes

I found out what it was I tried to show user token from $user->tokens()->first()->id But it is not a token

Really we get tokens from $this->user->createToken($name)->accessToken and not from db