相关疑难解决方法(0)

使用 Passport 密码授予和/或 Guzzle 时服务器冻结

我们正在将 Laravel 网站改造成 Laravel SPA,并在未来将其改造成使用 Web 应用程序的移动应用程序,因此我们需要某种 API 身份验证。为此,我们使用 Laravel Passport。

我一直在使用 Laravel 5.5 并遵循文档上的指南,但是当我尝试使用 postman 的新登录时,服务器冻结,HTTP 请求永远不会处理。

经过一些调试,我发现当我使用 Guzzle 发布到 /oauth/token 路由时,它崩溃了。但是当我使用 Postman 访问该路由时,没有问题。

这是我的代码:

    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(), …
Run Code Online (Sandbox Code Playgroud)

laravel laravel-passport

5
推荐指数
1
解决办法
2093
查看次数

Guzzle 无法向本地主机发出 GET 请求(端口:80、8000、8080 等)

目前使用 Laravel 5.5 和与 Laravel 安装程序一起提供的 Guzzle。

我正在尝试发出 GET 请求(其他 HTTP 请求也会发生错误),但似乎不起作用。

此代码不起作用:

public function callback(Request $request)
{
    $code = $request->code;

    $client = new Client(['exceptions' => false]);

    try {
      $response = $client->request('GET', 'http://localhost/api/tests');
        // $response = $http->request('POST', Config::get('app.url') . '/oauth/token', [
        //     'form_params' => [
        //         'grant_type' => 'authorization_code',
        //         'client_id' => Config::get('oauth_client.client_id'),
        //         'client_secret' => Config::get('oauth_client.client_secret'),
        //         'redirect_uri' => Config::get('oauth_client.redirect_uri'),
        //         'code' => $code,
        //     ],
        // ]);
        // return json_decode((string) $response->getBody(), true);
    } catch (\Exception $e) {
        dd($e); …
Run Code Online (Sandbox Code Playgroud)

php http laravel guzzle laravel-artisan

2
推荐指数
1
解决办法
3144
查看次数

标签 统计

laravel ×2

guzzle ×1

http ×1

laravel-artisan ×1

laravel-passport ×1

php ×1