使用Google App Engine与Laravel和Socialite

3
我在通过socialite使用Google oauth登录时遇到了问题。我正在将目前在本地和生产环境中正常运行的应用程序迁移到GAE。
我正在使用适用于Laravel 5.1的shpasser gae包,它正常工作。 第一个登录请求显示了像应该一样的 Google 权限屏幕,但在回调中,我得到了一个 curl 错误。
cURL error 7: (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
in CurlFactory.php line 168
at CurlFactory::createRejection(object(EasyHandle), array('errno' => '7', 'error' => '', 'url' => 'https://accounts.google.com/o/oauth2/token', 'content_type' => null, 'http_code' => '0', 'header_size' => '0', 'request_size' => '0', 'filetime' => '-1', 'ssl_verify_result' => '0', 'redirect_count' => '0', 'total_time' => '0', 'namelookup_time' => '0.080153', 'connect_time' => '0', 'pretransfer_time' => '0', 'size_upload' => '0', 'size_download' => '0', 'speed_download' => '0', 'speed_upload' => '0', 'download_content_length' => '-1', 'upload_content_length' => '-1', 'starttransfer_time' => '0', 'redirect_time' => '0', 'redirect_url' => '', 'primary_ip' => '', 'certinfo' => array(), 'primary_port' => '0', 'local_ip' => '', 'local_port' => '0')) in CurlFactory.php line 132

我尝试更改 Laravel 使用的 Guzzle 包中的证书位置为:

 final public function setSslVerification($certificateAuthority = true, $verifyPeer = true, $verifyHost = 2)
    {
        $opts = $this->config[self::CURL_OPTIONS] ?: array();

        if ($certificateAuthority === true) {
            // use bundled CA bundle, set secure defaults
            $opts[CURLOPT_CAINFO] = __DIR__ . '/etc/ca-certificates.crt';
            $opts[CURLOPT_SSL_VERIFYPEER] = true;
            $opts[CURLOPT_SSL_VERIFYHOST] = 2;
        } elseif ($certificateAuthority === false) {
            unset($opts[CURLOPT_CAINFO]);
            $opts[CURLOPT_SSL_VERIFYPEER] = false;
            $opts[CURLOPT_SSL_VERIFYHOST] = 0;
        } elseif ($verifyPeer !== true && $verifyPeer !== false && $verifyPeer !== 1 && $verifyPeer !== 0) {
            throw new InvalidArgumentException('verifyPeer must be 1, 0 or boolean');
        } elseif ($verifyHost !== 0 && $verifyHost !== 1 && $verifyHost !== 2) {
            throw new InvalidArgumentException('verifyHost must be 0, 1 or 2');
        } else {
            $opts[CURLOPT_SSL_VERIFYPEER] = $verifyPeer;
            $opts[CURLOPT_SSL_VERIFYHOST] = $verifyHost;
            if (is_file($certificateAuthority)) {
                unset($opts[CURLOPT_CAPATH]);
                $opts[CURLOPT_CAINFO] = $certificateAuthority;
            } elseif (is_dir($certificateAuthority)) {
                unset($opts[CURLOPT_CAINFO]);
                $opts[CURLOPT_CAPATH] = $certificateAuthority;
            } else {
                throw new RuntimeException(
                    'Invalid option passed to ' . self::SSL_CERT_AUTHORITY . ': ' . $certificateAuthority
                );
            }
        }

        $this->config->set(self::CURL_OPTIONS, $opts);

        return $this;
    }

但仍然出现相同的错误。我在php.ini文件中也有这个设置。
; enable function that are disabled by default in the App Engine PHP runtime
google_app_engine.enable_functions = "php_sapi_name, php_uname, getmypid"
google_app_engine.allow_include_gs_buckets = "my-bucket-name"
allow_url_include = 1
extension = "curl.so"
google_app_engine.enable_curl_lite = “1

除了重新使用Guzzle进行登录并查看是否仍然出现错误之外,我已经没有其他选择了,而不是使用Socialite重新登录。

更新 文档中指出,您不能同时启用curl lite和full curl。这已经改变,所以只有extension =“curl.so”在php.ini文件中。这并没有解决问题,但需要更改。


我越看越觉得,Google App Engine可能正在阻止我的响应。 - Chris Townsend
1个回答

2

在进行大量谷歌搜索和研究后,我已经成功解决了这个问题,同时也要感谢来自这个问题的用户Omega。

Laravel Socialite使用Guzzle包,但是在Google应用引擎上安装时,该包无法找到证书文件。最近的提交已添加以下行:

// Google app engine
+        '/etc/ca-certificates.crt',

默认的ca_bundle函数
中,如果您没有更新到最新的Guzzle,请添加此行。该目录为

vendor/guzzlehttp/guzzle/src/functions.php

请确保您的php.ini文件中未启用curl.so扩展。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接