Save AT and timestamp in file

@param string $access_token
@param int $timestamp

@return bool
192848
private function save($access_token, $time)
    {
        unset($this->runtime_file_content);

        $bytes = @file_put_contents($this->getFilePath(), json_encode(['a' => $access_token, 'e' => $time]));

        if ($bytes === false) {
            // fatal log will throw an exception
            $this->logger->fatal(__CLASS__, 'store', sprintf('Unable to store access token in %s', $this->getFilePath()));
        }

        $this->logger->debug(__CLASS__, 'store', sprintf('Access token stored in %s', $this->getFilePath()));

        return true;
    }
11321
private function timestampHasExpired($timestamp) {
        $year   = substr($timestamp, 0, 4);
        $month  = substr($timestamp, 5, 2);
        $day    = substr($timestamp, 8, 2);
        $hour   = substr($timestamp, 11, 2);
        $minute = substr($timestamp, 14, 2);
        $second = substr($timestamp, 17, 2);

        $timestamp = gmmktime($hour, $minute, $second, $month, $day, $year);

        $diff = time() - $timestamp;

        if ($diff > $this->maxDiff || $diff < -$this->maxDiff) {
            return true;
        }

        return false;
    }
454341
public function setExpireAtMilliSeconds(int $timestamp): bool
    {
        return $this->handle->pExpireAt($this->name, $timestamp);
    }
387596
private function appendTimestamp($filename, $queryString, $timestamp = null)
    {
        // current timestamp as default
        $timestamp = $timestamp === null ? time() : $timestamp;

        return $filename . '?' . urlencode($queryString) . '=' . $timestamp;
    }
633668
function timestamp(schema, options) {
	options = options || {};
	// Set defaults
	options = Object.assign({
		createdName: 'createdAt',
		updatedName: 'updatedAt',
		disableCreated: false,
		disableUpdated: false
	}, options);

	// Add fields if not disabled
	if (!options.disableCreated) {
		addSchemaField(schema, options.createdName, {type: Date});
	}
	if (!options.disableUpdated) {
		addSchemaField(schema, options.updatedName, {type: Date});
	}

	// Add pre-save hook to save dates of creation and modification
	schema.pre('save', preSave);

	/**
	 * Callback for the schema pre save
	 *
	 * @this mongoose.Schema
	 * @param {Function} next The next pre save callback in chain
	 * @returns {undefined}
	 */
	function preSave(next) {
		const _ref = this.get(options.createdName);

		if (!options.disableUpdated) {
			this[options.updatedName] = new Date();
		}
		if (!options.disableCreated && (_ref === undefined || _ref === null)) {
			this[options.createdName] = new Date();
		}

		next();
	}
}
1192079
protected function saveAccessToken($token) {
		$this->setState('auth_token', $token['access_token']);
		$this->setState('expires', isset($token['expires_in']) ? time() + (int)$token['expires_in'] - 60 : 0);
		$this->access_token = $token['access_token'];
	}
337439
function setTimeStamp( $timestamp )
    {
        $date = getdate( $timestamp );
        $this->Time = $date[ 'hours' ] * self::SECONDS_AN_HOUR +
                      $date[ 'minutes' ] * self::SECONDS_A_MINUTE +
                      $date[ 'seconds' ];
    }
353586
public function expireat($key, $timestamp)
    {
        $this->init();
        $result = $this->driver->expireat($key, $timestamp);
        return (bool)$result;
    }
960884
public function isFresh(int $timestamp): bool
    {
        if (!$this->maxTimestamp && !empty($this->resources)) {
            $this->maxTimestamp = max(array_map('filemtime', $this->resources));
        }

        return $this->maxTimestamp <= $timestamp;
    }
323274
public function setAccessTokenExpire($access_token_expire)
    {
        //Store expiry date as unix timestamp (now + expires in)
        $access_token_expire = time() + $access_token_expire;
        $this->access_token_expire = $access_token_expire;
        $config = SiteConfig::current_site_config();
        $config->HailAccessTokenExpire = $access_token_expire;
        $config->write();
    }
470415
public function setAccessToken($access_token)
    {
        $key = array_search('access_token', $this->persistantMap);
        if ($key !== false) {
            $this->store->set('access_token', $access_token);
        }

        $this->access_token = $access_token;

        return $this;
    }
841539
public static function dirtyDecode($access_token, $claims = [])
    {
        $now = time();
        $expecting = false;
        $incorrect = false;
        $expired = false;
        $error = false;
        $errors = array();
        $decodedToken = array();
        $token_segments = explode('.', $access_token);
        $body = (isset($token_segments[1])) ? $token_segments[1] : null;

        if (count($token_segments) != 3) {
            $error = true;
            $errors[] = "Token has wrong number of segments";
        }
        if (null === $data = static::jsonDecode(static::urlDecode($body))) {
            $error = true;
            $errors[] = "Decoder has problem with Token encoding";
        }
        if (isset($data->nbf) && $data->nbf > $now) {
            $expecting = true;
        }
        if (isset($data->iat) && $data->iat > $now) {
            $incorrect = true;
        }
        if (isset($data->exp) && $now >= $data->exp) {
            $expired = true;
        }

        $decodedToken =  array(
            'token_id' => (isset($data->jti)) ? $data->jti : null,
            'user_id' => (isset($data->sub)) ? $data->sub : null,
            'expecting' => $expecting,
            'start_at_unix' => (isset($data->nbf)) ? $data->nbf : null,
            'start_at' => (isset($data->nbf)) ? date(DateTime::ISO8601, $data->nbf) : null,
            'incorrect' => $incorrect,
            'created_at_unix' => (isset($data->iat)) ? $data->iat : null,
            'created_at' => (isset($data->iat)) ? date(DateTime::ISO8601, $data->iat) : null,
            'expired' => $expired,
            'expires_at_unix' => (isset($data->exp)) ? $data->exp : null,
            'expires_at' => (isset($data->exp)) ? date(DateTime::ISO8601, $data->exp) : null,
            'error' => $error,
            'errors' => $errors,
            'valid' => ($expecting || $incorrect || $expired || $error) ? false : true
        );

        if(!empty($claims)){
            $decodedToken['claims'] = static::getCustomClaims($data, $claims);
        }

        return $decodedToken;
    }
333160
public function setTimestamp($timestamp)
    {
        if (self::$_immutable) {
            self::$_immutable = false;
            $newDate = clone $this;
            $newDate->setTimestamp($timestamp);
            self::$_immutable = true;

            return $newDate;
        } else {
            return parent::setTimestamp($timestamp);
        }
    }
170717
public function updateBitlyAccessToken($access_token)
    {
        $activeSystem = $this->getActiveSystem();
        $activeSystem->setBitlyAccessToken($access_token);
        $this->em->persist($activeSystem);
        $this->em->flush();
    }
179640
private function cacheToken(AccessToken $accessToken)
    {
        $tz = self::TIME_ZONE;
        $kvs = $this->getKeyValueStorage();

        $liveTimeInSec = Carbon::createFromTimestamp($accessToken->getExpires(), $tz)->diffInSeconds(Carbon::now($tz));

        $kvs->set(self::ACCESS_TOKEN_KEY, $accessToken->getToken());
        $kvs->expire(self::ACCESS_TOKEN_KEY, $liveTimeInSec);
        $kvs->set(self::REFRESH_TOKEN_KEY, $accessToken->getRefreshToken());
    }
441738
protected function _createFileVersion($timestamp = null) {
		if (!is_int($timestamp)) {
			$timestamp = time();
		}

		$result = dechex($timestamp);

		return $result;
	}
230784
public function getAccessToken($access_token)
	{
		// create access token
		$token = \Components\Developer\Models\Accesstoken::oneByToken($access_token);

		// make sure we have a token
		if (!$token->get('id'))
		{
			return false;
		}

		// make sure its a published token
		if (!$token->isPublished())
		{
			return false;
		}

		// get the application's client id
		$application = \Components\Developer\Models\Application::oneOrFail($token->get('application_id'));
		$token->set('client_id', $application->get('client_id'));

		// format expires to unix timestamp
		$token->set('expires', with(new Date($token->get('expires')))->toUnix());

		// return token
		return $token->toArray(true);
	}