你能帮我解决谷歌 oauth2 的身份验证问题吗?

问题描述

我在 google 上的 oauth 身份验证遇到了一个小问题,我在几篇文章中看到修改 etc 主机,但是我应该添加什么,因为我想我尝试了一切。如果您有任何建议..谢谢,stef

<?PHP 

require 'vendor/autoload.PHP';
require 'config.PHP';

use GuzzleHttp\Client;

$client = new Client([
    'timeout' => 2.0,'verify' => __DIR__ . '/cacert.pem'

    ]);
try 
{
$response = $client-> request('GET','https://accounts.google.com/.well-kNown/openid-configuration');
$discoveryJSON = json_decode((string)$response->getBody());
$tokenEndpoint = $discoveryJSON->token_endpoint;
$userinfoEndpoint = $discoveryJSON->userinfo_endpoint;
$response = $client->request('POST',$tokenEndpoint,[
'form_params'=>[
    'code' => $_GET['code'],'client_id' => GOOGLE_ID,'client_secret' => GOOGLE_SECRET,'redirect_uri' => 'http://localhost/oauth2/connect.PHP','grant_type' => 'authorization_code'
]]);

$accesstoken = json_decode($response->getBody())->access_token;

$response = $client->request('GET','$userinfoEndpoint',[
'headers' => [
    'Authorization' => 'Bearer ' . $accesstoken]

]);
$response = json_decode($response->getBody());

if ($response->email_verified === true) {
    session_start();
    $_SESSION['email'] = $response->email;
    header('Location: http://localhost/oauth2/secret.PHP');
    exit();

                                        }
}

catch (\GuzzleHttp\Exception\ClientException $exception) {
    dd($exception->getMessage());  } ?> 

my message error

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)