title: Unexpected Value exception
body: <p>I am having below error in postman while i was teting my api. It shows slim application error in postman. Error Type: UnexpectedValueException</p>
  
  <p>Message: Wrong number of segments</p>
  
  <p>File: C:\Users\tahmeed\Documents\app-timber-api2\vendor\firebase\php-jwt\src\JWT.php</p>
  
  <p>Line: 78</p>
  
  <p>Do i need to modify the token or the JWT.php ?</p>
  
  <p><strong>decode.php in JWT.php</strong></p>
  
  <pre><code>public static function decode($jwt, $key, array $allowed_algs = array())
  {
      $timestamp = is_null(static::$timestamp) ? time() : static::$timestamp;
  
      if (empty($key)) {
          throw new InvalidArgumentException('Key may not be empty');
      }
      $tks = explode('.', $jwt);
      if (count($tks) != 3) {
          throw new UnexpectedValueException('Wrong number of segments');
      }
      list($headb64, $bodyb64, $cryptob64) = $tks;
      if (null === ($header = static::jsonDecode(static::urlsafeB64Decode($headb64)))) {
          throw new UnexpectedValueException('Invalid header encoding');
      }
      if (null === $payload = static::jsonDecode(static::urlsafeB64Decode($bodyb64))) {
          throw new UnexpectedValueException('Invalid claims encoding');
      }
      if (false === ($sig = static::urlsafeB64Decode($cryptob64))) {
          throw new UnexpectedValueException('Invalid signature encoding');
      }
      if (empty($header-&gt;alg)) {
          throw new UnexpectedValueException('Empty algorithm');
      }
      if (empty(static::$supported_algs[$header-&gt;alg])) {
          throw new UnexpectedValueException('Algorithm not supported');
      }
      if (!in_array($header-&gt;alg, $allowed_algs)) {
          throw new UnexpectedValueException('Algorithm not allowed');
      }
      if (is_array($key) || $key instanceof \ArrayAccess) {
          if (isset($header-&gt;kid)) {
              if (!isset($key[$header-&gt;kid])) {
                  throw new UnexpectedValueException('"kid" invalid, unable to lookup correct key');
              }
              $key = $key[$header-&gt;kid];
          } else {
              throw new UnexpectedValueException('"kid" empty, unable to lookup correct key');
          }
      }
  
      // Check the signature
      if (!static::verify("$headb64.$bodyb64", $sig, $key, $header-&gt;alg)) {
          throw new SignatureInvalidException('Signature verification failed');
      }
  
      // Check if the nbf if it is defined. This is the time that the
      // token can actually be used. If it's not yet that time, abort.
      if (isset($payload-&gt;nbf) &amp;&amp; $payload-&gt;nbf &gt; ($timestamp + static::$leeway)) {
          throw new BeforeValidException(
              'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload-&gt;nbf)
          );
      }
  
      // Check that this token has been created before 'now'. This prevents
      // using tokens that have been created for later use (and haven't
      // correctly used the nbf claim).
      if (isset($payload-&gt;iat) &amp;&amp; $payload-&gt;iat &gt; ($timestamp + static::$leeway)) {
          throw new BeforeValidException(
              'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload-&gt;iat)
          );
      }
  
      // Check if this token has expired.
      if (isset($payload-&gt;exp) &amp;&amp; ($timestamp - static::$leeway) &gt;= $payload-&gt;exp) {
          throw new ExpiredException('Expired token');
      }
  
      return $payload;
  }
  </code></pre>
  
  <pre><code>AuthController.php
  
          &lt;?php
  
      namespace App\Controllers\AppodMobile;
      use \Psr\Http\Message\ServerRequestInterface as Request;
      use \Psr\Http\Message\ResponseInterface as Response;
      use \Interop\Container\ContainerInterface as ContainerInterface;
      use \Illuminate\Database\Query\Expression as Raw;
  
      use App\Models\AppodMobile\Users as Users;
      use Firebase\JWT\JWT;
      use Tuupola\Base62;
  
      class AuthController
      {
          use \App\CommonFunctions;
          protected $container;
  
          public function __construct(ContainerInterface $container) {
              $this-&gt;container = $container;
          }
  
  
          function auth($request,$response)
          {
              $input = $request-&gt;getParsedBody();
              $user = Users::select('id','pword')-&gt;where('email','=',$input['email'])-&gt;first();
  
              // verify email address.
              if(!$user) {
                  $response-&gt;withStatus(404);
                  return $response-&gt;withJson(['error' =&gt; true, 'message' =&gt; 'User does not exist.'],404);
              }
              // verify password.
              $salt = getenv('TMS_SALT');
              if (!(sha1($salt.$input['password']) == $user-&gt;pword)) {
                  $response-&gt;withStatus(401);
                  return $response-&gt;withJson(['error' =&gt; true, 'message' =&gt; 'Password is incorrect.'],401);
              }
              $now = new \DateTime();
              $future = new \DateTime("+120 minutes");
              $server = $request-&gt;getServerParams();
              $jti = (new Base62)-&gt;encode(random_bytes(16));
              $payload = [
                  "iat" =&gt; $now-&gt;getTimeStamp(),
                  // "exp" =&gt; $future-&gt;getTimeStamp(),
                  "jti" =&gt; $jti,
                  "sub" =&gt; $server["PHP_AUTH_USER"]
              ];
              $token = JWT::encode($payload, getenv('JWT_SECRET'), "HS256");
              $data = array(
                  'token' =&gt; $token,
                  'user_id'=&gt;$user-&gt;id,
                  // appod'expires' =&gt; $future-&gt;getTimestamp()
              );
              $response-&gt;withStatus(200);
              return $response-&gt;withJson($data);
          }
  
      }
  
  
  </code></pre>