PHPackages                             plhw/hf-api-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. plhw/hf-api-client

ActiveLibrary

plhw/hf-api-client
==================

PLHW API Client provides means to authenticate clients against with OAuth2 server and issue authorized requests to our api endpoints

3.0.0(2y ago)0763[2 issues](https://github.com/plhw/hf-api-client/issues)[5 PRs](https://github.com/plhw/hf-api-client/pulls)proprietaryPHPPHP ^7.4 | ^8.0

Since Feb 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/plhw/hf-api-client)[ Packagist](https://packagist.org/packages/plhw/hf-api-client)[ RSS](/packages/plhw-hf-api-client/feed)WikiDiscussions main Synced 2mo ago

READMEChangelog (2)Dependencies (12)Versions (33)Used By (0)

PLHW Api Client
===============

[](#plhw-api-client)

PLHW API Client provides means to authenticate clients against our OAuth2 server and issue authorized requests to our api endpoints.

Installation
------------

[](#installation)

```
composer require plhw/hf-api-client
```

Example API calls
-----------------

[](#example-api-calls)

Once you have succesfully installed the application, some example scripts are located at. To use them first copy an configuration file to your app root.

```
cp ./vendor/plhw/hf-api-client/example/.hf-api-client-secrets.php.dist ./.hf-api-client-secrets.php
```

Open `.hf-api-client-secrets.php` and configure it with credentials you got from us.

Finally the example scripts are configured to use `data/cache` as directory for its cached accss tokens. This directory must exist (only for the examples).

Now you can run the example scripts;

```
php ./vendor/plhw/hf-api-client/example/practicesPos.php
```

Usage
-----

[](#usage)

To implement usage in your application you can have a look at the example scripts.

```
$options = \HF\ApiClient\Options\Options::fromArray(
    [
        'server_uri'    => 'https://api.plhw.nl',
        'client_id'     => 'id',
        'client_secret' => 'secret',
        'scope'         => 'customer_pos',
        'grant_type'    => 'client_credentials',
    ]
);

$api = \HF\ApiClient\ApiClient::createClient($options, /* $cache OPTIONAL */);
```

The above is all that is nessesary to configure, though I recommend you tweak the caching meganism. Currently we use the [zendframework/zend-cache](https://docs.zendframework.com/zend-cache/) component. This might change when v3 is released to use the psr-7 caching FIG standard.

When you have `ApiClient` instance you can use it by calling methods as defined in `/vendor/plhw/hf-api-client/data/v1` on it. Additionally [API documentation](https://api.plhw.nl/docs) can be found here.

for example, search the published practices around a coordinate.

```
$results = $api->customer_posAroundCoordinate('52.3629882,4.8593175', 15000, 'insoles');

if ($api->isSuccess()) {
    foreach ($results['data'] as $result) {
        printf("Practice %s on %skm\n", $result['attributes']['name'],
            round(($result['attributes']['distance'] / 100)) / 10);
        printf(" - sells %s\n", implode(', ', $result['attributes']['products']));
    }
} else {
    printf("Error (%d): %s\n", $api->getStatusCode(), $result);
}
```

Under the hood
--------------

[](#under-the-hood)

When you call any method on the APIClient instance an access token is requested from our OAuth2 server. This access token is then cached for aditional uses up to the moment it expires or is deleted. It will then get a new access token.

Any calls to our API are now `signed` with that access token and is used by our permission system to determain if you have access or not.

Our API will accept and return json payload with are automaticly (de)encoded.

### OAuth2 ClientCredentialsGrant

[](#oauth2-clientcredentialsgrant)

For machine to machine communication OAuth2 ClientCredentialGrant is appropiate. You must obtain the following information from us.

1. client ID
2. client secret
3. scope

Your client side application should communicate via a proxy to our server.

```

   [webbrowser]    [application]    [api.plhw.nl]

1.  request data    -> request ->      do we have valid access token?

2.                                     NO, get access token   -> request  -> id,secret,scope

3.                                                                                validate request

4.                                     store token in cache    validate token

6.                                     data
