Jwt-auth: JWT payload does not contain the required claims

Created on 21 Feb 2018  路  2Comments  路  Source: tymondesigns/jwt-auth

Subject of the issue

I don't want to use Laravel's user credentials to create a token so I am trying to create based on anything. I tried to follow the instructions from the wiki under the the heading "Creating a Token based on anything you like" and I get an error.

Your environment

| Q | A
| ----------------- | ---
| Bug? | Yes
| Framework | Laravel
| Framework version | 5.6
| Package version | 0.5.*
| PHP version | 7.2.0

Steps to reproduce

Run the code from the wiki:

$customClaims = ['foo' => 'bar', 'baz' => 'bob'];
$payload = JWTFactory::make($customClaims);
$token = JWTAuth::encode($payload);

Expected behaviour

I guess we should have a valid JWT?

Actual behaviour

I get an exception:
JWT payload does not contain the required claims

Most helpful comment

Had to use this:

$factory = JWTFactory::customClaims([
    'sub'   => env('API_ID'),
]);

$payload = $factory->make();
$token = JWTAuth::encode($payload);
return ['HTTP_Authorization' => "Bearer {$token}"];

All 2 comments

Had to use this:

$factory = JWTFactory::customClaims([
    'sub'   => env('API_ID'),
]);

$payload = $factory->make();
$token = JWTAuth::encode($payload);
return ['HTTP_Authorization' => "Bearer {$token}"];

If you want to decode information from encoded string.

$jwtToken = new Tymon\JWTAuth\Token('<your encoded string token>');
$decoded = Tymon\JWTAuth\Facades\JWTAuth::decode($jwtToken);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

lloy0076 picture lloy0076  路  3Comments

therealmjk picture therealmjk  路  3Comments

agneshoving picture agneshoving  路  3Comments

johncloud200 picture johncloud200  路  3Comments

gamelife1314 picture gamelife1314  路  3Comments