public function validateCredentials(Credentials $credentials)
 {
     // Validate $credentials here, then assign to $claims an array
     // containing the JWT claims to associate with the generated token.
     // EKW: Successful validation assumed
     $tokenId = base64_encode(mcrypt_create_iv(32));
     $issuedAt = time();
     $notBefore = $issuedAt + 10;
     // Adding 10 seconds
     $expire = $notBefore + 864000;
     // Adding 30 days for example
     $serverName = gethostname();
     // Retrieve the server name from config file
     $data = array(Constants::USER_ID => $credentials->getUserId(), Constants::ROLE => $credentials->getRole());
     $claims = array('iat' => $issuedAt, 'jti' => $tokenId, 'iss' => $serverName, 'nbf' => $notBefore, 'exp' => $expire, 'data' => $data);
     return $this->generator->getToken($claims);
 }
 /**
  * Validates a set of user credentials.
  *
  * - If the user credentials are valid, a new authentication token is
  *   created and a corresponding Token instance is returned.
  * - If the user credentials are invalid, an InvalidException instance is
  *   thrown.
  * - If for some reason the user credentials cannot be validated, an
  *   AuthException instance is thrown.
  *
  * @param \Spark\Auth\Credentials $credentials
  * @return \Spark\Auth\Token
  * @throws \Spark\Auth\Exception\InvalidException if an invalid auth token
  *         is specified
  * @throws \Spark\Auth\Exception\AuthException if another error occurs
  *         during authentication
  */
 public function validateCredentials(Credentials $credentials)
 {
     #var_dump($credentials);
     $offered_identifier = $credentials->getIdentifier();
     $offered_password = $credentials->getPassword();
     $expected_identifier = $this->credentials->getIdentifier();
     $expected_password = $this->credentials->getPassword();
     if ($offered_identifier == $expected_identifier && $offered_password == $expected_password) {
         // generate a random token string
         $token_string = bin2hex(openssl_random_pseudo_bytes(16));
         $metadata = array('username' => $offered_identifier, 'expiration' => date(DateTime::ATOM, strtotime('+1 hour')));
         $token = new Token($token_string, $metadata);
         // update the token in the database and set the expiration date-time
         $this->valid_tokens->updateToken($token);
     } else {
         throw new InvalidException();
     }
     return $token;
 }