V
V
Vasek182017-05-16 23:25:26
API
Vasek18, 2017-05-16 23:25:26

How to make tokens in Laravel 5.3 Passport with dots?

I upgraded my Laravel project from 5.2 to 5.3 in order to use Laravel Passport and use it to authorize by a token through api.
A few weeks later, I'm still suffering with an authorization error (Unauthenticated error). After tens of hours of studying the Internet on this issue, I started debugging the code of the package itself and this is what I realized:
My problem is revealed in this file \vendor\lcobucci\jwt\src\Parser.php, namely in this method:

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;
    }

The point is that in the tokens that I receive through
$this->user->createToken($this->user->id.' Access Token')->accessToken;

There is no dot, so explode doesn't work and everything crashes with an exception. A typical token that I get looks like this :
1369781b342d5181072c7f2859a54102f1dc992f6367c4b8ac37193799ec893438ad1b6ac43af3ae Forums unfortunately didn't help me Asking the community to help me with this problem Thanks in advance for any help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasek18, 2017-05-21
@Vasek18

I found something wrong
I tried to show the token to the user via $user->tokens()->first()->id
But it's not a token, it's an ID of some entity in the database
Just similar to
the token We get the real code of the token from $this- >user->createToken($name)->accessToken
And this is the value that needs to be returned and shown

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question