微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决你能帮我解决谷歌 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 举报,一经查实,本站将立刻删除。