使用Passport密码授予和/或Guzzle时服务器冻结 [英] Server Freezing when using Passport Password Grants and/or Guzzle

查看:58
本文介绍了使用Passport密码授予和/或Guzzle时服务器冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将laravel网站改编为laravel SPA,将来还会使用该Web应用程序的移动应用程序,因此我们需要某种API身份验证.我们正在使用Laravel Passport.

We're adapting a laravel website into a laravel SPA, and in the future, a Mobile App that uses the web app, so we need some sort of API authentication. We're using Laravel Passport for that.

我一直在使用Laravel 5.5,并遵循文档上的指南,但是当我尝试使用带邮递员的新登录名时,服务器冻结,HTTP请求不再处理.

I've been using Laravel 5.5 and following the guide on the Docs, but when I try using the new login with postman, the server freezes, the HTTP requests never processing.

经过一些调试后,我发现当我使用Guzzle将其发布到/oauth/token路由时,它会崩溃.但是当我使用邮递员访问那条路线时,我没有问题.

After some debugging, I found out that it crashes when I use Guzzle to post into the /oauth/token route. But when I use Postman to access that route, I have no problem.

这是我的代码:

    public function login(Request $request){
    $http = new Client();

    var_dump(1);
    //die
    $response = $http->post('http://localhost:8000/oauth/token', [  //Con postman esta ruta funciona
            'form_params' => [
            'grant_type' => 'password',
            'client_id' => env('PASSWORD-CLIENT_ID',2),
            'client_secret' => env('PASSWORD-CLIENT_SECRET',2),
            'username' => $request->username, //parece usar correo, no nombre de usuario
            'password' => $request->password,
            'scope' => '*',
        ],
    ]);

    var_dump(2);
    //die;
    return json_decode((string) $response->getBody(), true);
}

这是Guzzle还是Oauth/Passport的问题?

Is this a problem with Guzzle, Or with Oauth/Passport?

推荐答案

如果您正在寻找一种快速的修补程序来测试您的更新-您可以通过打开两个命令提示符来完成此操作.第一个将运行php artisan serve(在本地,我的默认端口是8000,而您将在http://localhost:8000上运行您的站点).第二个将运行php artisan serve --port 8001.

If you are looking for a quick fix to test your updates - you can get this done by opening up two command prompts. The first would be running php artisan serve (locally my default port is 8000 and you would be running your site on http://localhost:8000). The second would run php artisan serve --port 8001.

然后,您将发布请求更新为:

Then you would update your post request to:

$response = $http->post('http://localhost:8001/oauth/token', [ 
        'form_params' => [
        'grant_type' => 'password',
        'client_id' => env('PASSWORD-CLIENT_ID',2),
        'client_secret' => env('PASSWORD-CLIENT_SECRET',2),
        'username' => $request->username,
        'password' => $request->password,
        'scope' => '*',
    ],
]);

这应该在测试期间有所帮助,直到您能够访问服务器或本地虚拟主机上的所有内容为止.

This should help during your testing until you are able to everything on server or a local virtual host.

这篇关于使用Passport密码授予和/或Guzzle时服务器冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆