title: Why is JWT::decode() returning { "status": "\"kid\" empty, unable to lookup correct key" }
body: <p>My first ever Stack Overflow Question - here it goes!</p>
  <p>I've encoded a Firebase JWT token to authenticate a 'buyer' in my PHP Slim API. It encodes correctly and generates a JWT token in Postman,</p>
  <p><a href="https://i.stack.imgur.com/THjor.png" rel="noreferrer">Postman JWT encoding</a></p>
  <p>but when I try to use the JWT for Bearer Authentication to access a group of protected routes in my routes.php file, I receive:</p>
  <p><code>{ &quot;status&quot;: &quot;\&quot;kid\&quot; empty, unable to lookup correct key&quot; }</code></p>
  <p>Here's my generateJWT() function: - in Buyer.php class.</p>
  <pre><code>    {
          $buyer = $buyer =  self::findOrFail($id);
          if (!$buyer) {
              return false;
          }
          $key = self::JWT_KEY;
          $expiration = time() + self::JWT_EXPIRE;
          $issuer = 'Lab03_I425.com';
          $token = [
              'iss' =&gt; $issuer,
              'exp' =&gt; $expiration,
              'isa' =&gt; time(),
              'data' =&gt; [
                  'uid' =&gt; $id,
                  'name' =&gt; $buyer-&gt;username,
                  'email' =&gt; $buyer-&gt;email] ];
          return JWT::encode (
              $token,
              $key,
              'HS256',
          );
      }
  </code></pre>
  <p>And here's my validateJWT() function: - - - - in Buyer.php class</p>
  <pre><code>    public static function validateJWT($token)
      {
          return JWT::decode($token, self::JWT_KEY,  array('HS256') );
      }
  </code></pre>
  <p>I am aware there is a JWT parameter $kid that exists beyond the $payload, $key, $alg params, but I was under the impression it is not necessary to complete authentication. I'm new to using Slim, Tokens, and Web Services so any help would be greatly appreciated.</p>
  <p>Here's the authJWT method in my BuyerController.php that is called in routes.php:</p>
  <pre><code>public function authJWT(Request $request, Response $response)
      {
          $params = $request-&gt;getParsedBody();
          $username = $params['username'];
          $password = $params['user_password'];
          $authBuyer = Buyer::authenticateBuyer($username, $password);
          if ($authBuyer) {
              $status_code = 200;
              $jwt = Buyer::generateJWT($authBuyer-&gt;id);
              $results = [
                  'status' =&gt; 'login successful',
                  'jwt' =&gt; $jwt,
                  'name' =&gt; $authBuyer-&gt;username
              ];
          } else {
              $status_code = 401;
              $results = [
                  'status' =&gt; 'login failed',
              ];
          }
          //return $results;
          return $response-&gt;withJson($results, $status_code,
              JSON_PRETTY_PRINT);
      }
  </code></pre>
  <p>I looked in the - - - - - vendor\firebase\php-jwt\src\JWT.php - - - - file and noticed</p>
  <pre><code>if (empty($kid)) {
              throw new UnexpectedValueException('&quot;kid&quot; empty, unable to lookup correct key');
          }
  </code></pre>
  <p>If I understand correctly, this value can be a string or null, and apparently mine is empty (a string of 0 length) if its returning the aboe UnexpectedValueException().</p>
  <p>Why is this? and how can I change this so my JWT middleware allows me to access my grouped routes?</p>
  <p>Thank you in advance for your feedback and guidance.</p>