Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Google登录和后端身份验证_Php_Reactjs_Google Signin - Fatal编程技术网

Php Google登录和后端身份验证

Php Google登录和后端身份验证,php,reactjs,google-signin,Php,Reactjs,Google Signin,我遵循了GoogleSignin的教程,它在客户端工作得很好。我已经尝试导出令牌服务器端,但在config.php文件中不断出现500错误。我变得糊涂了:/如果你能看到我在努力做什么,我错过了什么 config.php <?php //config.php session_start(); require_once('../vendor/autoload.php'); $google_client = new Google_Client(); $googl

我遵循了GoogleSignin的教程,它在客户端工作得很好。我已经尝试导出令牌服务器端,但在config.php文件中不断出现500错误。我变得糊涂了:/如果你能看到我在努力做什么,我错过了什么

config.php

<?php
//config.php
    session_start();
    require_once('../vendor/autoload.php');
    $google_client = new Google_Client();

    $google_client->setClientId($CLIENT_ID);
    $google_client->setClientSecret($CLIENT_SECRET);

    $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    $google_client->setRedirectUri($redirect_uri);

    $google_client->addScope('email');
    $google_client->addScope('profile');

?>
已解决:)

我有几个问题:

  • Axios POST的路径不正确-只需要基本的相对路径

  • 我的配置文件只需要供应商路径和客户机ID变量

  • 我没有处理JSON帖子,现在我在Google上输入了代码,所有的工作都是:)

    $CLIENT_ID]);//指定访问后端的应用程序的客户端ID $payload=$client->verifyIdToken($post['code']); 如果($有效载荷){ $userid=$payload['sub']; //如果请求指定了G套件域: //$domain=$payload['hd']; echo$payload['email']; }否则{ //无效的ID令牌 回声“失败”; } ?>

  • $CLIENT\u ID
    $CLIENT\u SECRET
    从哪里来?请将它们设置为正确的Google凭据:)不确定为什么它会因为缺乏研究而被否决-我已经探索了Google API,遵循了一些教程,我只是被这个axios帖子卡住了。注意:我已经更新了今天测试中的一些代码,当前我在本地测试时从外部服务器获得了net::ERR_CONNECTION_densed]500。您检查了服务器上的错误日志了吗?
    $client
    在哪里实例化?
    <?php 
    include('config.php');
      if (isset($_POST['code'])) {
          $token = $client->fetchAccessTokenWithAuthCode($_POST['code']);
        
     
        if(!isset($token['error'])){
    
          $google_client->setAccessToken($token['access_token']);
    
          $_SESSION['access_token'] = $token['access_token'] ;
    
          $google_service = new Google_Service_0auth2($google_client);
    
          $data = $google_service->userinfo->get();
    
          if(!empty($data[email])){
            $_SESSION['user_email'] = $data['email'];
          }
    
        }
    
      }
    ?>
    
     const responseGoogle = response => {       
                setName(response.profileObj.name);
                setUrl(response.profileObj.imageUrl);
                const postData = { code: response.tokenId };
                // Send a POST request                  
               axios({
                method: 'POST',
                url: "http://localhost:80/php/createJSON.php",
                headers: {
                  "Access-Control-Allow-Origin": "*"
                },
              //  headers: axiosConfig,
                data: postData
                })
                .then((response) => {
                    console.log('RESPONSE.DATA '+response.data);
                }, (error) => {
                    console.log(error);
                });