我正在跟随here关于laravel护照的laracast教程,我跟着教程完全一样。
但是当我在请求授权时单击授权按钮时出现此错误
Client error: `POST http://laravelserver.local/oauth/token` resulted in a `401 Unauthorized` response:
{"error":"invalid_client","message":"Client authentication failed"}
是否会出现在laravel 5.4中的某种错误?因为本教程适用于laravel 5.3
就像在教程中我创建了2个laravel app,laravelserver.local和laravelclient.local
在laravelserver中我安装护照和身份验证,也使用护照vue组件。
然后我创建laravelclient.local,我也安装了护照,还安装了guzzlehttp。这是我的路线
use Illuminate\Http\Request;
Route::get('/',function(){
$query = http_build_query([
'client_id' => 3,
'redirect_uri' => 'http://laravelclient.local/callback',
'response_type' => 'code',
'scope' => '',
]);
return redirect('http://laravelserver.local/oauth/authorize?'.$query);
});
Route::get('/callback', function(Request $request){
$http = new GuzzleHttp\Client;
$response = $http->post('http://laravelserver.local/oauth/token',[
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 3,
'client_secret' => 'sVyq48StpzKfivvimxcRKPzIhek0cgDhfPx4kWqo',
'redirect_uri' => 'http://laravelclient.local/callback',
'code' => $request->code,
]
]);
return json_decode((string) $response->getBody(), true);
});
并在我的laravelserver数据库中(使用mysql,因为我在Windows 10上运行XAMPP中的所有内容) oauth_clients表我有3条记录
并且在oauth_auth_codes表中只有1条记录
user_id :1, id :8a07951bae2aa50a55ed615785800681d7a5dbd44beccea26638bb43bf218c8e573da5f303a56082, client_id :3,范围:[],已撤销:0, expires_at :2017-07-21 07:30:15
所以它就像在那个教程中一样,我也发现这个问题已在github中提出,但没有正确的答案
更新
我也在主机文件中添加了这个
127.0.0.1 laravelserver.local
127.0.0.1 laravelclient.local
并将其添加到httpd-vhosts.conf
<VirtualHost laravelserver.local:80>
DocumentRoot "C:\xampp\htdocs\laravelserver\public"
ServerAdmin laravelserver.local
<Directory "C:\xampp\htdocs\laravelserver">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost laravelclient.local:80>
DocumentRoot "C:\xampp\htdocs\laravelclient\public"
ServerAdmin laravelclient.local
<Directory "C:\xampp\htdocs\laravelclient">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>