2017-10-28 9 views
1

guzzleを使用してトークンリクエストを行い、 "400 Bad Request`レスポンスを受信しようとしています:{" error ":" invalid_client "}"。私は問題なくcURLとHTTP_Request2で同じ要求を行うことができます。Guzzle - 400 Bad Request`レスポンス:{"error": "invalid_client"} - トークンリクエストを行うとき

<?php 
    require 'vendor/autoload.php'; 
    use GuzzleHttp\Client; 
    use GuzzleHttp\Exception\RequestException; 
    use GuzzleHttp\Psr7\Request; 

    session_start(); 
    if(isset($_GET['code'])){ 
     $code = $_GET['code']; 
     $encodeB64 = base64_encode('{clientID}:{clientSecret}'); 
     $client = new GuzzleHttp\Client(); 
     $response = $client->request('POST', 'https://identity.reckon.com/connect/token',[ 
     ['headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],['Authorization' => 'Basic '.$encodeB64]], 
     ['body' => ['grant_type' => 'authorization_code'],['code' => $code],['redirect_uri' => '{redirectURI}']] 
     ]); 
     $body = $response->getBody(); 
     echo $body; 
    } 

これらは、このAPIでトークン要求を作成する方法の詳細です:

URL:https://identity.reckon.com/connect/token

タイプ:POSTが

ボディ:grant_type = authorization_code &コード= {コード} & redirect_uri = {リダイレクトURL}

ヘッダー:

  • のContent-Type =アプリケーション/ x-www-form-urlencodedで

  • 承認:基本:私はどこわからない{クライアントIDをbase64でエンコードされたクライアントシークレット}

間違っている。

+0

試み[と]これらだけで表現されていますまたはコード内で実際にどのように実装されているかなどです。 –

答えて

0

私はそれを試しました。答えは以下の通りであった:そのは内APIサーバーにも、これらのエンクロージャを送っ取得する前に、文字列の上に起こって何かがあるかもしれないAPIサーバーに送信されたリクエスト文字列をチェックする

<?php 
    require 'C:/Users/Shane/vendor/autoload.php'; 
    use GuzzleHttp\Client; 
    use GuzzleHttp\Exception\RequestException; 
    use GuzzleHttp\Psr7\Request; 

    session_start(); 
    if(isset($_GET['code'])){ 
     $code = $_GET['code']; 
     $encodeB64 = base64_encode('{client id}:{client secret}'); 
     $authbody = 'grant_type=authorization_code&code='.$code.'&redirect_uri={redirect url}'; 
     $client = new GuzzleHttp\Client(); 
     $response = $client->request('POST', 'https://identity.reckon.com/connect/token',['headers' => 
      ['Content-Type' => 'application/x-www-form-urlencoded','Authorization' => 'Basic '.$encodeB64], 
      'body' => $authbody]); 
     $body = $response->getBody(); 
     echo $body;