php - Laravel 护照 oauth/授权错误

标签 php laravel oauth-2.0 laravel-passport

我尝试使用 oauth/authorize 来使用 Passport,以便允许 Web 应用程序稍后获取代码和请求 token ,但我收到错误

Route [login] not defined

下面是我的代码。

客户端代码

    // First route that user visits on consumer app
Route::get('/', function () {
    // Build the query parameter string to pass auth information to our request
    $query = http_build_query([
        'client_id' => 3,
        //'client_secret' => 'MtkEmBL0f0Bf4LcEPcOBUS0wLHvF5xqqchhCpaTH',
        'redirect_uri' => 'http://client.app:8082/callback',
        'response_type' => 'code',
        'scope' => ''
    ]);

    // Redirect the user to the OAuth authorization page
    return redirect('http://server.app:8082/oauth/authorize?' . $query);
});


// Route that user is forwarded back to after approving on server
Route::get('/callback', function (Request $request) {
    return 'test 2';
    $http = new GuzzleHttp\Client;

    $response = $http->post('http://server.app:8082/oauth/token', [
        'form_params' => [
            'grant_type' => 'authorization_code',
            'client_id' => 3, // from admin panel above
            'client_secret' => 'MtkEmBL0f0Bf4LcEPcOBUS0wLHvF5xqqchhCpaTH', // from admin panel above
            'redirect_uri' => 'http://client.app:8082/callback',
            'code' => $request->code // Get code from the callback
        ]
    ]);

    // echo the access token; normally we would save this in the DB
    return json_decode((string) $response->getBody(), true)['access_token'];
});

oauth/authorize request error

oauth/authorize request error

最佳答案

也许您有多个错误。看起来您忘记定义通用身份验证路由。从 php artisan make:auth 或 Auth::routes() 开始。 OAuth 路由没有 login 路由,您收到的错误表明您没有定义 login 路由。它实际上是在 Auth::routes() 中定义的。

关于php - Laravel 护照 oauth/授权错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46145166/

相关文章:

php - 在 Mac OS X 10.5.8 上为 PHP 安装 Mcrypt 扩展

laravel - 如何在 Laravel 中连接 with 运算符的结果?

mysql - Laravel 在体育中的 Eloquent 关系

php - 如何在所有 Blade View 中获取全局用户配置文件数据?

oauth-2.0 - 尝试检索 Oauth access_token 时出现 AADSTS50146 错误

javascript - 如何设置表格中单选按钮选择的限制?

php - 为什么要插入额外的可用列?

javascript - 在哪里存储访问和刷新 token

php - 用于 php 的自动映射器?

azure - 使用 oauth azure 数据工厂进行分页