2017-10-28 1 views
1

guzzle을 사용하여 토큰 요청을하려고하는데 "400 Bad Request"응답을받습니다 : { "error ":"invalid_client "}". 나는 cURL과 HTTP_Request2로 아무런 문제없이 동일한 요청을 할 수있다.Guzzle - 400 Bad Request` 응답 : { "error": "invalid_client"} - 토큰 요청을 할 때

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

유형 : POST

바디 : grant_type = authorization_code & 코드 = {코드

<?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와 토큰 요청을하는 방법의 세부 사항입니다 } & redirect_uri = {리디렉션 url}

헤더 :

  • 콘텐츠 유형 = 응용 프로그램/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; 
관련 문제