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.
| Q | A
| ----------------- | ---
| Bug? | Yes
| Framework | Laravel
| Framework version | 5.6
| Package version | 0.5.*
| PHP version | 7.2.0
Run the code from the wiki:
$customClaims = ['foo' => 'bar', 'baz' => 'bob'];
$payload = JWTFactory::make($customClaims);
$token = JWTAuth::encode($payload);
I guess we should have a valid JWT?
I get an exception:
JWT payload does not contain the required claims
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);
Most helpful comment
Had to use this: