3

当我请求 url 重定向时,我无法获取 access_token,它总是重定向到登录

// First route that user visits on consumer app
Route::get('/redirect', function () {
    // Build the query parameter string to pass auth information to our request
    $query = http_build_query([
        'client_id' => 1,
        'redirect_uri' => 'http://app_golf.xiongmaojf.com/callback',
        'response_type' => 'code',
        'scope' => 'crud-bookmark-collections crud-bookmark-tags crud-bookmarks'
    ]);
// var_export($query);
    // Redirect the user to the vOAuth authorization page
    return redirect('http://golf.xiongmaojf.com/oauth/authorize?' . $query);
});

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

    $response = $http->post('http://golf.xiongmaojf.com/oauth/token', [
        'form_params' => [
            'grant_type' => 'authorization_code',
            'client_id' => 1, // from admin panel above
            'client_secret' => 'LNJhtWdGsDTQmei9x4lAh2BBfOmQkqXG3jdOjGRL', // from admin panel above
            'redirect_uri' => 'http://app_golf.xiongmaojf.com/callback',
            'code' => $request->code // Get code from the 
        ]
    ]);

    return json_decode((string) $response->getBody(), true)['access_token'];
});

但请求 url oauth/authorize,我无法获取令牌,它总是重定向到登录,

我解决了这个问题,因为我没有登录,对此我很抱歉,但是当我登录时,请求 url oauth/authorize ,它总是需要 golf.xiongmaojf.com 的用户名和密码,任何用户名和密码没用,

在此处输入图像描述

如果我点击取消它回应

{
    "error": "invalid_client",
    "message": "Client authentication failed"
}

我通过 reigster new app_client use oauth/clients 解决了这个问题,并得到了这个页面 在此处输入图像描述

我得到了 access_token

4

2 回答 2

0

删除所有 oauth 表:

php artisan migrate:rollback --step=5

并迁移所有:

 php artisan migrate

和:

 php artisan passport:install --force
于 2017-10-22T22:17:18.873 回答
0

确保在提供程序中创建新的 OAuth 客户端时提供了相同的 URL http://app_golf.xiongmaojf.com/callback 。

当您的 url 不同时,可以显示此对话框。

如果没有帮助,请尝试使用以下方法生成新密钥:

php artisan passport:keys
于 2017-10-27T09:17:28.737 回答