phpurigoogle-signingoogle-api-php-clientphp-openssl

Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: > Connection refused for URI https://www.googleapis.com/oauth2/v3/certs


I have a very big problem with my connection in my web app.

First of all the app is in progress so I use the localhost to test my php code. I wanted to use the Google api to connect users so I use : PHP 8.1.20, composer 2.5.8 and "google/apiclient" 2.15.0.

The error I get on my Mozilla page is :

Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: Connection refused for URI https://www.googleapis.com/oauth2/v3/certs in C:\UwAmp\www\mysite\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php:329 etc

My php code for login is :

<?php
// print_r($_COOKIE);
// print_r($_POST);
if (!empty($_POST['credential'])) {
    if (empty($_COOKIE['g_csrf_token']) || empty($_COOKIE['g_csrf_token']) || $_COOKIE['g_csrf_token'] != $_POST['g_csrf_token']) {
        echo "Erreur vérification jeton CSRF";
        exit();
    }

    $clientID = "numbers.apps.googleusercontent.com";
    $client = new Google_Client(['client_id' => $clientID]);  // Specify the CLIENT_ID of the app that accesses the backend

    $idToken = $_POST['credential'];
    $user = $client->verifyIdToken($idToken);
    // print_r($user);
    if ($user) {
        $_SESSION['user'] = $user;
        header("Location: profil.php");
        exit();
    } else {
        echo "Erreur lors de l'authentification";
    }
}

(the comments are in french)

I've searched for the last two days but don't find anything working, so if someone is up to date with the recent php and google api client version I'm fine with it. Thanks in advance.


Solution

  • SOLUCE : I found it and I search for 4 entire days ! It was the openssl extension that was activated on the wrong php.ini file. So to be sure check your php_wamp.ini file and on your actual php folder the php.ini file only, check those lines with a ctrl+f like they are under :

    extension_dir = "ext" 
    extension=openssl 
    ;openssl.cafile
    ;openssl.capath
    

    Of course if you use composer check that the extension=curl is uncomment and use the most recent version of it and google/apiclient.