【问题标题】:Passport Authedication Error in laravel 5.5laravel 5.5中的护照验证错误
【发布时间】:2017-10-27 11:58:38
【问题描述】:
Error creating resource: [message] fopen(http://127.0.0.1:8000/oauth/token): failed to open stream: HTTP request failed! [file] /var/www/html/local/api-sample-application/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php [line] 324

我在尝试实现 laravel 护照身份验证时收到此错误。

这是我在 routes/web.php 内容中的代码:

Route::get('/redirect', function () {
$query = http_build_query([
    'client_id'     => '3',
    'redirect_uri'  => 'http://127.0.0.1:8000/oauth/callback',
    'response_type' => 'code',
    'scope'         => '',
]);

return redirect('http://127.0.0.1:8000/oauth/authorize?' . $query);

}); Route::get('/oauth/callback', function () {

$http = new GuzzleHttp\Client;

if (request('code')) {
    $response = $http->post('http://127.0.0.1:8000/oauth/token', [
        'form_params' => [
            'grant_type'    => 'authorization_code',
            'client_id'     => '3',
            'client_secret' => 'H1UQCKVRARwASEJLR4ugGjBHHvFy34SCzSJFqQLL',
            'redirect_uri'  => 'http://127.0.0.1:8000/oauth/callback',
            'code'          => request('code'),
        ],
    ]);

    return json_decode((string)$response->getBody(), TRUE);
} else {
    return response()->json(['error' => request('error')]);
}

});

当我点击此URL 时,我收到此错误,无法生成令牌。

Error message screenshot

【问题讨论】:

    标签: laravel-5.5 guzzle


    【解决方案1】:

    我也遇到了同样的问题,1天后我找到了原因……

    由于 PHP 内置服务器是单线程的,在您的服务器上请求另一个 url 将停止第一个请求并超时。

    所以你不能在同一个线程中从本地主机请求本地主机。

    你可以很容易地检查它,尝试'get'来公共服务器主机,'http://www.example-host.com'..

    检查这个http://stackoverflow.com/a/25651196/916682

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-02
      • 2020-11-12
      • 2019-03-08
      • 2018-05-04
      • 2018-05-02
      • 2020-08-27
      • 2016-10-19
      • 1970-01-01
      相关资源
      最近更新 更多