shanhuhai / oauth2-demo

3 stars 4 forks source link

400 Bad Request:Client credentials were not found in the headers or body #1

Open gzroy2015 opened 6 years ago

gzroy2015 commented 6 years ago

Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: POST http://oauth2-server.dev/token.php resulted in a 400 Bad Request response: {"error":"invalid_client","error_description":"Client credentials were not found in the headers or body"} '

gzroy2015 commented 6 years ago

在这里有人也提出类似问题 https://github.com/bshaffer/oauth2-server-php/issues/531

解决方法: client.php

$client = new GuzzleHttp\Client();
$response = $client->request('POST', SERVER_URL.'/token.php', [
    'auth' => [CLIENT_ID, CLIENT_SECRET],

    'form_params'=> [
        'grant_type'=>'authorization_code',
        'code'=> $code,
        'redirect_uri'=> REDIRECT_URI,

        'client_id'=>CLIENT_ID,
        'client_secret'=>CLIENT_SECRET,
    ]
]);