moodle/moodle · error · Google_Auth_Exception

Expiration time too far in future

Error message

Expiration time too far in future: %s

What it means

Thrown by verifySignedJwtWithCerts() when the JWT's 'exp' claim is at or beyond now + max_expiry — the token was issued with an unreasonably far-future expiration (or the cert max expiry is too small), so it is rejected as potentially fraudulent.

Solutions

  1. Reduce the token lifetime at issuance so exp is within the allowed window (Google ID tokens: <= 1 hour).
  2. If your use case legitimately needs longer-lived tokens, pass a larger $max_expiry to verifySignedJwtWithCerts/verifyIdToken.
  3. Check for clock problems: a badly wrong client clock can distort the comparison less often than a bad exp, but verify server time is NTP-synced.

Example fix

// before
$payload = $client->verifyIdToken($token); // default max_expiry=1h, token valid 30 days
// after
$payload = $client->verifyIdToken($token, $audience, $issuer, 60 * 60 * 24 * 30);
Defensive patterns

Strategy: validation

Validate before calling

$maxExpiry = 3600;
$payload = json_decode(base64_decode(str_replace(['-','_'],['+','/'], explode('.', $token)[1]) . '=='), true);
if (isset($payload['exp']) && $payload['exp'] >= time() + $maxExpiry) {
  throw new InvalidArgumentException('Token lifetime exceeds allowed max expiry');
}

Type guard

function expWithinLimit(array $payload, $maxExpiry) { return isset($payload['exp']) && $payload['exp'] < time() + $maxExpiry; }

Try / catch

try {
  $payload = $client->verifyIdToken($token);
} catch (Google_Auth_Exception $e) {
  if (strpos($e->getMessage(), 'Expiration time too far in future') !== false) {
    // shorten token lifetime at issuance or raise max_expiry
  }
  throw $e;
}

Prevention

When it happens

Trigger: verifySignedJwtWithCerts() (via verifyIdToken/verifySignedJwt) called with a token whose exp exceeds now + $max_expiry — e.g. default 1-hour limit exceeded, or the caller passed a small $max_expiry while using a long-lived token.

Common situations: Minting your own JWT with a multi-day/month expiry and validating it with verifyIdToken()'s default max_expiry; or passing a deliberately short $max_expiry argument that conflicts with your issuer's token lifetime.

Related errors


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/b49c31578ec0a9bf. Report an issue: GitHub.

Appendix: source

Thrown at public/lib/google/src/Google/Auth/OAuth2.php:578

    if (array_key_exists("iat", $payload)) {
      $iat = $payload["iat"];
    }
    if (!$iat) {
      throw new Google_Auth_Exception("No issue time in token: $json_body");
    }
    $earliest = $iat - self::CLOCK_SKEW_SECS;

    // Check expiration timestamp
    $now = time();
    $exp = 0;
    if (array_key_exists("exp", $payload)) {
      $exp = $payload["exp"];
    }
    if (!$exp) {
      throw new Google_Auth_Exception("No expiration time in token: $json_body");
    }
    if ($exp >= $now + $max_expiry) {
      throw new Google_Auth_Exception(
          sprintf("Expiration time too far in future: %s", $json_body)
      );
    }

    $latest = $exp + self::CLOCK_SKEW_SECS;
    if ($now < $earliest) {
      throw new Google_Auth_Exception(
          sprintf(
              "Token used too early, %s < %s: %s",
              $now,
              $earliest,
              $json_body
          )
      );
    }
    if ($now > $latest) {
      throw new Google_Auth_Exception(
          sprintf(

View on GitHub (pinned to 48ea8c3322)