首页 > 解决方案 > 无法授权或获取令牌

问题描述

我无法让 laravel 应用程序访问另一个 laravel 应用程序(同一服务器)中的 api 端点。我可以让它在终端和邮递员中工作,但不能从 laravel 应用程序本身,既获得身份验证令牌,又在邮递员和终端中使用工作,但不能在 laravel 中使用。(杀了我,这是前几天的工作)

我尝试了许多 Guzzle 和 curl 配置,在 Win 10 上使用 WAMP。Laravel 框架版本 5.3.31,PHP 7.2.18

try {
            $response = $http->request('POST',$this->base_oauth_url. 'oauth/token', [
                'headers' => [
                    'Accept' => 'application/json',
                    'Content-Type' => 'application/x-www-form-urlencoded',
                ],
                'form_params' => [
                    'grant_type' => 'password',
                    'client_id' => self::API_CLIENT_ID,
                    'client_secret' => self::API_SECRET,
                    'username' => self::API_USERNAME,
                    'password' => self::API_PASSWORD,
                    'scope' => '*',
                ],
                'debug'=>$this->debug,
                'allow_redirects' => false,
                'verify' => false,

            ]);

        } catch (ClientException $e) {
            throw new Exception("Guzzle Error: {$e->getMessage()}");

        } catch (Exception $e) {
            throw new Exception("Send Error: ({$e->getCode()}): {$e->getMessage()}");
        }

        $response = json_decode((string) $response->getBody()->getContents());
        $data = array();
        $data['access_token'] = $response->access_token;
        $data['refresh_token'] = $response->refresh_token;

错误:Guzzle 错误:客户端错误:POST http://mytestdomain.com/oauth/token导致401 Unauthorized响应:{"error":"invalid_client","message":"Client authentication failed"}

标签: laraveloauth-2.0guzzlelaravel-passport

解决方案


推荐阅读