2017-03-14 22:12:58 +00:00
|
|
|
|
|
|
|
# MetaTech PwsClient
|
|
|
|
|
|
|
|
a php webservice client managing [ PwsAuth ](https://github.com/meta-tech/pws-auth) protocol
|
|
|
|
|
|
|
|
### Requirements
|
|
|
|
|
|
|
|
PHP >= 5.4
|
|
|
|
|
|
|
|
### Install
|
|
|
|
|
2017-03-15 01:51:35 +00:00
|
|
|
The package can be installed using [ Composer ](https://getcomposer.org/).
|
2017-03-14 22:12:58 +00:00
|
|
|
```
|
|
|
|
composer require meta-tech/pws-client
|
|
|
|
```
|
|
|
|
|
|
|
|
Or add the package to your `composer.json`.
|
|
|
|
|
|
|
|
```
|
|
|
|
"require": {
|
2017-03-15 22:51:19 +00:00
|
|
|
"meta-tech/pws-client" : "^1.3"
|
2017-03-14 22:12:58 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Usage
|
|
|
|
When instantiating, PwsClient automatically checks if it has been authenticated. Otherwise, or if the session has expired,
|
|
|
|
the client will perform the authentication. Then, you can initiate get or post call
|
|
|
|
|
|
|
|
```php
|
|
|
|
<?php
|
|
|
|
require_once(__dir__ . '/vendor/autoload.php');
|
|
|
|
|
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
use MetaTech\PwsAuth\Authenticator;
|
|
|
|
use MetaTech\Ws\Client;
|
|
|
|
|
|
|
|
$config = Yaml::parse(file_get_contents(__dir__ . '/config/pwsauth.yml'));
|
|
|
|
$authenticator = new Authenticator($config);
|
|
|
|
|
2017-03-14 22:18:39 +00:00
|
|
|
$config = Yaml::parse(file_get_contents(__dir__ . '/config/pwsclient.yml'));
|
2017-03-14 22:12:58 +00:00
|
|
|
$client = new Client($config, $authenticator);
|
|
|
|
// on instanciation the client init this calls :
|
|
|
|
// $client->check();
|
2017-03-14 22:18:39 +00:00
|
|
|
// enventually $client->call() (depending on previous response);
|
2017-03-14 22:12:58 +00:00
|
|
|
|
|
|
|
// get example
|
|
|
|
$response = $client->get('/ws/person/222');
|
|
|
|
if ($response->done) {
|
|
|
|
// do stuff
|
|
|
|
|
|
|
|
}
|
|
|
|
// post example
|
2017-03-15 22:51:19 +00:00
|
|
|
$response = $client->post('/ws/person/222/update', [ 'firstname' => 'toto']);
|
2017-03-14 22:12:58 +00:00
|
|
|
if ($response->done) {
|
|
|
|
// do stuff
|
|
|
|
}
|
|
|
|
|
2017-03-14 22:18:39 +00:00
|
|
|
// to close and destroy session on serverside :
|
|
|
|
// $client->logout();
|
2017-03-14 22:12:58 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
### Config
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# pwsclient config
|
|
|
|
|
|
|
|
# 0 : disable, 1 : verboose, 2 : most verboose
|
|
|
|
debug : 1
|
|
|
|
protocol : https://
|
|
|
|
hostname : pwsserver.docker
|
2017-03-16 01:24:37 +00:00
|
|
|
# ssl options
|
|
|
|
verifypeer : 0
|
|
|
|
verifyhost : 0
|
2017-03-14 22:12:58 +00:00
|
|
|
# file storing the server 's session id - must be out of DocumentRoot and read/writable by server
|
|
|
|
store : wsess
|
|
|
|
login : test
|
|
|
|
password : test
|
|
|
|
key : test
|
|
|
|
# 0 : display cli, 1 : display html
|
|
|
|
html_output : 0
|
|
|
|
# http authentication
|
|
|
|
http :
|
|
|
|
user :
|
|
|
|
password :
|
|
|
|
# server uris for authentication
|
|
|
|
uri :
|
|
|
|
auth : /ws/auth
|
|
|
|
logout : /ws/logout
|
|
|
|
check : /ws/isauth
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
### Server Response
|
|
|
|
|
2017-03-14 22:18:39 +00:00
|
|
|
PwsClient intend to receiv any JsonResponse, the structure of the response is free.
|
|
|
|
However, meta-tech always return this simple Json Structure :
|
|
|
|
`{ done : boolean, msg : 'string contextual msg', data : whatever }`
|
2017-03-14 22:12:58 +00:00
|
|
|
|
2017-03-15 01:51:35 +00:00
|
|
|
see [ meta-tech/pws-server ](https://github.com/meta-tech/pws-server)
|
2017-03-15 22:51:19 +00:00
|
|
|
and [ meta-tech/silex-core ](https://github.com/meta-tech/silex-core)
|
2017-03-14 22:12:58 +00:00
|
|
|
|
|
|
|
### License
|
|
|
|
|
|
|
|
The project is released under the MIT license, see the LICENSE file.
|