Ich habe Taylor Otwells Frontend/Backend-Pass Beispiel aus Laracast repliziert, auf einem lokalen Host-Fenster: Backend und Frontend 127.0.0.1:8000 läuft läuft 127.0.0.:8080 Wenn ich einen Client-aPI-Aufruf versuchen - 127.0.0.1:8080/callback bekomme ich diese:Laravel Pass oauth: Client Fehler: `POST http: //127.0.0.1: 8000/oauth/token` führte zu einer` 400 Bad Request` Antwort:
ClientException in RequestException.php line 111:
Client error: `POST http://127.0.0.1:8000/oauth/token`
resulted in a `400 Bad Request` response:
{"error":"invalid_request","message":"The request is missing a required
parameter, includes an invalid parameter value, (truncated...)
und dieses Detail:
at Client request('post','http://127.0.0.1:8000/oauth/token',
array('form_params' => array('grant_type' => 'authorization_code',
'client_id' => 3,
'client_secret' =>'23GCROVkVMtQqKsJKmx2xPojiDU4TOOe3ZMvKvQh',
'redirect_uri' =>'http://127.0.0.1:8080/callback', 'code' => null),
'synchronous' =>true)) in Client.php line 87
at Client->__call('post', array('http://127.0.0.1:8000/oauth/token',
array('form_params' =>array('grant_type' => 'authorization_code',
'client_id' => 3,
'client_secret' =>'23GCROVkVMtQqKsJKmx2xPojiDU4TOOe3ZMvKvQh',
'redirect_uri' => 'http://127.0.0.1:8080/callback', 'code' => null))))in web.php line 3
Hier der entsprechende Code ist:
Route::get('/callback', function() {
$query = http_build_query([
'client_id' => 3,
'redirect_uri' => 'http://127.0.0.1:8080/callback',
'response_type' => 'code',
'scope' => ''
]);
return redirect('http://127.0.0.1:8000/oauth/authorize?'.$query);
});
Route::get('/callback', function (Request $request) {
$http = new GuzzleHttp\Client;
$response = $http->post('http://127.0.0.1:8000/oauth/token',[
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 3,
'client_secret' => '23GCROVkVMtQqKsJKmx2xPojiDU4TOOe3ZMvKvQh',
'redirect_uri' => 'http://127.0.0.1:8080/callback',
'code' => $request -> code,
],
]);
return json_decode((string) $response->getBody(),true);
Schätzen Sie irgendwelche Vorschläge
(FYI, ich habe HasApiTokens in User-Modell sowie alle anderen Anforderungen einrichten. Ich frage mich, ob es etwas damit zu tun hat, Laravel-Client und Laravel-Back-End auf lokalen Host auszuführen).