googleapis / google-api-php-client

A PHP client library for accessing Google APIs
Apache License 2.0
9.22k stars 3.52k forks source link

Class "phpseclib3\Math\BigInteger\Engines\OpenSSL" not found in /home/{user}/public_html/oAuth/vendor/phpseclib/phpseclib/phpseclib/Math/BigInteger/Engines/PHP/OpenSSL.php:23 #2503

Closed eliezercazares closed 10 months ago

eliezercazares commented 10 months ago

Environment details

Steps to reproduce

  1. ... Follow the set up instructions.
  2. ... up to the point where you want to run an example
  3. ... Run example idtoken.php

Code example

# example
<?php
/*
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

include_once __DIR__ . '/../vendor/autoload.php';
include_once "templates/base.php";

echo pageHeader("Retrieving An Id Token");

/*************************************************
 * Ensure you've downloaded your oauth credentials
 ************************************************/
if (!$oauth_credentials = getOAuthCredentialsFile()) {
    echo missingOAuth2CredentialsWarning();
    return;
}

/************************************************
 * NOTICE:
 * The redirect URI is to the current page, e.g:
 * http://localhost:8080/idtoken.php
 ************************************************/
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

$client = new Google\Client();
$client->setAuthConfig($oauth_credentials);
$client->setRedirectUri($redirect_uri);
$client->setScopes('email');

/************************************************
 * If we're logging out we just need to clear our
 * local access token in this case
 ************************************************/
if (isset($_REQUEST['logout'])) {
    unset($_SESSION['id_token_token']);
}

/************************************************
 * If we have a code back from the OAuth 2.0 flow,
 * we need to exchange that with the
 * Google\Client::fetchAccessTokenWithAuthCode()
 * function. We store the resultant access token
 * bundle in the session, and redirect to ourself.
 ************************************************/
if (isset($_GET['code'])) {
    $token = $client->fetchAccessTokenWithAuthCode($_GET['code'], $_SESSION['code_verifier']);

    // store in the session also
    $_SESSION['id_token_token'] = $token;

    // redirect back to the example
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
    return;
}

/************************************************
  If we have an access token, we can make
  requests, else we generate an authentication URL.
 ************************************************/
if (
  !empty($_SESSION['id_token_token'])
  && isset($_SESSION['id_token_token']['id_token'])
) {
    $client->setAccessToken($_SESSION['id_token_token']);
} else {
    $_SESSION['code_verifier'] = $client->getOAuth2Service()->generateCodeVerifier();
    $authUrl = $client->createAuthUrl();
}

/************************************************
  If we're signed in we can go ahead and retrieve
  the ID token, which is part of the bundle of
  data that is exchange in the authenticate step
  - we only need to do a network call if we have
  to retrieve the Google certificate to verify it,
  and that can be cached.
 ************************************************/
if ($client->getAccessToken()) {
    $token_data = $client->verifyIdToken();
}
?>

<div class="box">
  <?php echo $redirect_uri; ?>
<?php if (isset($authUrl)) : ?>
  <div class="request">
    <a class='login' href='<?= $authUrl ?>'>Connect Me!</a>
  </div>
<?php else : ?>
  <div class="data">
    <p>Here is the data from your Id Token:</p>
    <pre><?php var_export($token_data) ?></pre>
  </div>
<?php endif ?>
</div>

<?= pageFooter(__FILE__);

Result:

[17-Sep-2023 16:55:42 UTC] PHP Fatal error:  Uncaught Error: Class "phpseclib3\Math\BigInteger\Engines\OpenSSL" not found in /home/o61vcrn7bs63/public_html/oAuth/vendor/phpseclib/phpseclib/phpseclib/Math/BigInteger/Engines/PHP/OpenSSL.php:23
Stack trace:
#0 /home/o61vcrn7bs63/public_html/oAuth/vendor/composer/ClassLoader.php(576): include()
#1 /home/o61vcrn7bs63/public_html/oAuth/vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}()
#2 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#3 /home/o61vcrn7bs63/public_html/oAuth/vendor/phpseclib/phpseclib/phpseclib/Math/BigInteger/Engines/Engine.php(227): class_exists()
#4 /home/o61vcrn7bs63/public_html/oAuth/vendor/phpseclib/phpseclib/phpseclib/Math/BigInteger.php(106): phpseclib3\Math\BigInteger\Engines\Engine::setModExpEngine()
#5 /home/o61vcrn7bs63/public_html/oAuth/vendor/phpseclib/phpseclib/phpseclib/Math/BigInteger.php(148): phpseclib3\Math\BigInteger::setEngine()
#6 /home/o61vcrn7bs63/public_html/oAuth/vendor/phpseclib/phpseclib/phpseclib/Math/BigInteger.php(167): phpseclib3\Math\BigInteger::initialize_static_variables()
#7 /home/o61vcrn7bs63/public_html/oAuth/src/AccessToken/Verify.php(236): phpseclib3\Math\BigInteger->__construct()
#8 /home/o61vcrn7bs63/public_html/oAuth/src/AccessToken/Verify.php(111): Google\AccessToken\Verify->getPublicKey()
#9 /home/o61vcrn7bs63/public_html/oAuth/src/Client.php(820): Google\AccessToken\Verify->verifyIdToken()
#10 /home/o61vcrn7bs63/public_html/oAuth/examples/idtoken.php(93): Google\Client->verifyIdToken()
#11 {main}
  thrown in /home/o61vcrn7bs63/public_html/oAuth/vendor/phpseclib/phpseclib/phpseclib/Math/BigInteger/Engines/PHP/OpenSSL.php on line 23

By the way, the class exists at the path. it's a small class inhereting from Progenitor... looks like this:

<?php

/**
 * OpenSSL Modular Exponentiation Engine
 *
 * PHP version 5 and 7
 *
 * @author    Jim Wigginton <terrafrost@php.net>
 * @copyright 2017 Jim Wigginton
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
 * @link      http://pear.php.net/package/Math_BigInteger
 */

namespace phpseclib3\Math\BigInteger\Engines\PHP;

use phpseclib3\Math\BigInteger\Engines\OpenSSL as Progenitor;

/**
 * OpenSSL Modular Exponentiation Engine
 *
 * @author  Jim Wigginton <terrafrost@php.net>
 */
abstract class OpenSSL extends Progenitor
{
}

I'll be around for any questions or comments.

Thank you! -eliezer

eliezercazares commented 10 months ago

UPDATE:

I think I have identified the culprit...

" Uncaught Error: Class "phpseclib3\Math\BigInteger\Engines\OpenSSL""

phpseclib3 should be phpseclib ?

eliezercazares commented 10 months ago

UPDATE:

I think it's an issue with the namespaces, I can do some explicit require_once() for classes and some errors go away.

BTW I downloaded the ZIP file instead of using Composer.

eliezercazares commented 10 months ago

UPDATE:

I saw in the Release Log that you guys recently updated phpseclib.

I took vendor/phpseclib/. from PHP v7.4 and I did an overwrite on vendor/phpseclib/. in PHP v8.0

This fixed all my issues.

I am on PHP 8.1.0. Using phpseclib from 7.4 on top of the latest release works!

You guys might need to check that out?

Thanks for the framework/repo, it's awesome! With some troubleshooting it works.

vishwarajanand commented 10 months ago

Thanks for the update @eliezercazares , I will mark this as closed.