4

Scenario

  • Remote APi with Oauth 2.0
  • App not work on mode web. Only console
  • Using Library Guzzle 2.0 (client)

On remote API Documentation

  • HTTPS -> POST https://ops.epo.org/3.2/auth/accesstoken
  • HTTP Headers Authorization- > Basic eTNBT0c4NnF3cWpVMFFVNjlWWUdUSjRKR3hVTjhFVkc6cnJYZHI1V0E3eDl 0dWRtUA==:
  • Contet-Type: application/x-www-form-urlencoded
  • POST request payload
  • grant_type=client_credentials

One url for use API tested:

http://ops.epo.org/3.2/rest-services/published-data/publication/docdb/EP1000000/biblio

Code

use GuzzleHttp\Client;

private function connectEPO 
{
    $base_uri           = 'https://ops.epo.org/3.2/';
    $urlAccessToken'    = 'https://ops.epo.org/3.2/auth/accesstoken', 
    $consumerKey        = 'mysecretkey';
    $consumerSecretKey  = 'myconsumersecretkey';

    $client = new Client([
        'base_uri'      => 'https://ops.epo.org/3.2/'
    ]);
    $response = $client->request('POST', 'auth/accesstoken', [
        'auth' => [$consumerKey,$consumerSecretKey]
    ]);
    dd($response); 
}

Error

[GuzzleHttp\Exception\ClientException]                                                                   
  Client error: `POST https://ops.epo.org/3.2/auth/accesstoken` resulted in a `400 Bad Request` response:  
  <error><code>400</code><message>Required param : grant_type</message>                                    
                        </error>                                                      

Also try

$client = new Client([
            'base_uri'      => 'https://ops.epo.org/3.2/'
        ]);
        $request = $client->post('auth/accesstoken', null, array(
            'consumerKey'               => $consumerKey',
            'consumerSecretKey'         => $consumerSecretKey,
            'grant_type'                => 'client_credentials'
        ));

        dd($request);

Error

  [GuzzleHttp\Exception\ClientException]                                                                    
  Client error: `POST https://ops.epo.org/3.2/auth/accesstoken` resulted in a `401 Unauthorized` response:  
  <error><code>401</code><message>Client identifier is required</message>                                   
                        </error>   

Try several options but I understand or I not see correct way on manual of Guzzle.

abkrim
  • 3,512
  • 7
  • 43
  • 69
  • If you want to use this it works for me: https://github.com/dunnleaddress/oauth2-client – Dung Aug 27 '17 at 16:20

0 Answers0