public function verifyIdToken($idToken, $audience = null)
  {
    if (empty($idToken)) {
      throw new LogicException('id_token cannot be null');
    }

    // set phpseclib constants if applicable
    $this->setPhpsecConstants();

    // Check signature
    $certs = $this->getFederatedSignOnCerts();
    foreach ($certs as $cert) {
      $bigIntClass = $this->getBigIntClass();
      $rsaClass = $this->getRsaClass();
      $modulus = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['n']), 256);
      $exponent = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['e']), 256);

      $rsa = new $rsaClass();
      $rsa->loadKey(array('n' => $modulus, 'e' => $exponent));

      try {
        $payload = $this->jwt->decode(
            $idToken,
            $rsa->getPublicKey(),
            array('RS256')
        );

        if (property_exists($payload, 'aud')) {
          if ($audience && $payload->aud != $audience) {
            return false;
          }
        }

        // support HTTP and HTTPS issuers
        // @see https://developers.google.com/identity/sign-in/web/backend-auth
        $issuers = array(self::OAUTH2_ISSUER, self::OAUTH2_ISSUER_HTTPS);
        if (!isset($payload->iss) || !in_array($payload->iss, $issuers)) {
          return false;
        }

        return (array) $payload;
      } catch (ExpiredException $e) {
        return false;
      } catch (ExpiredExceptionV3 $e) {
        return false;
      } catch (SignatureInvalidException $e) {
        // continue
      } catch (DomainException $e) {
        // continue
      }
    }

    return false;
  }
public function verifyIdToken($idToken, $audience = null)
  {
    if (empty($idToken)) {
      throw new LogicException('id_token cannot be null');
    }

    // set phpseclib constants if applicable
    $this->setPhpsecConstants();

    // Check signature
    $certs = $this->getFederatedSignOnCerts();
    foreach ($certs as $cert) {
      $bigIntClass = $this->getBigIntClass();
      $rsaClass = $this->getRsaClass();
      $modulus = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['n']), 256);
      $exponent = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['e']), 256);

      $rsa = new $rsaClass();
      $rsa->loadKey(array('n' => $modulus, 'e' => $exponent));

      try {
        $payload = $this->jwt->decode(
            $idToken,
            $rsa->getPublicKey(),
            array('RS256')
        );

        if (property_exists($payload, 'aud')) {
          if ($audience && $payload->aud != $audience) {
            return false;
          }
        }

        // support HTTP and HTTPS issuers
        // @see https://developers.google.com/identity/sign-in/web/backend-auth
        $issuers = array(self::OAUTH2_ISSUER, self::OAUTH2_ISSUER_HTTPS);
        if (!isset($payload->iss) || !in_array($payload->iss, $issuers)) {
          return false;
        }

        return (array) $payload;
      } catch (ExpiredException $e) {
        return false;
      } catch (ExpiredExceptionV3 $e) {
        return false;
      } catch (SignatureInvalidException $e) {
        // continue
      } catch (DomainException $e) {
        // continue
      }
    }

    return false;
  }
public function verifyIdToken ( $ idToken , $ audience = null ) { if ( empty ( $ idToken ) ) { throw new LogicException ( 'id_token cannot be null' ) ; } // set phpseclib constants if applicable $ this -> setPhpsecConstants ( ) ; // Check signature $ certs = $ this -> getFederatedSignOnCerts ( ) ; foreach ( $ certs as $ cert ) { $ bigIntClass = $ this -> getBigIntClass ( ) ; $ rsaClass = $ this -> getRsaClass ( ) ; $ modulus = new $ bigIntClass ( $ this -> jwt -> urlsafeB64Decode ( $ cert [ 'n' ] ) , 256 ) ; $ exponent = new $ bigIntClass ( $ this -> jwt -> urlsafeB64Decode ( $ cert [ 'e' ] ) , 256 ) ; $ rsa = new $ rsaClass ( ) ; $ rsa -> loadKey ( array ( 'n' => $ modulus , 'e' => $ exponent ) ) ; try { $ payload = $ this -> jwt -> decode ( $ idToken , $ rsa -> getPublicKey ( ) , array ( 'RS256' ) ) ; if ( property_exists ( $ payload , 'aud' ) ) { if ( $ audience && $ payload -> aud != $ audience ) { return false ; } } // support HTTP and HTTPS issuers // @see https://developers.google.com/identity/sign-in/web/backend-auth $ issuers = array ( self :: OAUTH2_ISSUER , self :: OAUTH2_ISSUER_HTTPS ) ; if ( ! isset ( $ payload -> iss ) || ! in_array ( $ payload -> iss , $ issuers ) ) { return false ; } return ( array ) $ payload ; } catch ( ExpiredException $ e ) { return false ; } catch ( ExpiredExceptionV3 $ e ) { return false ; } catch ( SignatureInvalidException $ e ) { // continue } catch ( DomainException $ e ) { // continue } } return false ; }
Verifies an id token and returns the authenticated apiLoginTicket.
Throws an exception if the id token is not valid.
The audience parameter can be used to control which id tokens are
accepted.  By default, the id token must have been issued to this OAuth2 client.

@param $audience
@return array the token payload, if successful
Verifies an id token and returns the authenticated apiLoginTicket . Throws an exception if the id token is not valid . The audience parameter can be used to control which id tokens are accepted . By default the id token must have been issued to this OAuth2 client .