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

therealmjk picture therealmjk  路  3Comments

Rasoul-Karimi picture Rasoul-Karimi  路  3Comments

phamduong picture phamduong  路  3Comments

gandra picture gandra  路  3Comments

aofdev picture aofdev  路  3Comments