0
votes
  • "laravel/framework": "5.7.*"
  • "tymon/jwt-auth": "dev-develop"

I am trying to create a JWT token with added custom claims, without auth (which means that I am not looking to create a token from credentials.) This is for the purpose of creating tokens that do not require logins, such as forgot/reset-password, etc.

  • using Tymon/JWTAuth (https://github.com/tymondesigns/jwt-auth) Since there was an issue with Latest Laravel, it was recommended to load the latest dev ( 1.0.x-dev ). I have tried the following code without avail:
  • class OTL extends Model implements JWTSubject
  • use JWTAuth;
  • use Tymon\JWTAuth\Contracts\JWTSubject;
  • use Tymon\JWTAuth\Facades\JWTFactory;

public static function getJwtToken($customerId, $action, $token){ $customClaims = ['action' => $action, 'customer-id' => $customerId, 'token' => $token]; $factory = JWTFactory::customClaims($customClaims); $payload = $factory->make(); $token = JWTAuth::encode($payload); return $token;

I am receiving an error: JWT payload does not contain the required claims.

I am expecting to receive the token that holds the payload above.

2
Hello, maybe it's the jwt-auth package that does not allow you to use the jwt token without the claims for authentication ? Maybe you should try to use native jwt library here jwt.io/#libraries-io ? You can also try to override the method that generate you the tokenFlyzzx

2 Answers

3
votes

I solved this problem by commenting out 'exp' in required_claims in the config/jwt.php:

.....
'required_claims' => [
   'iss',
   'iat',
   //'exp',
.....
],
1
votes

I just encountered the same error and was able to solve it by updating the list of required claims in the generated configuration file config/jwt.php.

...
'required_claims' => [
    'exp',
    'sub',
    ...
],
...

Also make sure you have run php artisan jwt:secret or otherwise provided a secret key for signing.