bernardosilva/jwt-api-client-php

为PHP准备的API客户端,用于使用JWT进行API调用

0.0.3 2018-01-15 15:05 UTC

README

Jason Web Token API客户端是一个库,用于简化需要JWT令牌进行认证的API的调用。

Latest Stable Version Total Downloads Build Status License

如何安装

$ composer require bernardosilva/jwt-api-client-php

如何使用

use BernardoSilva\JWTAPIClient\APIClient;
use BernardoSilva\JWTAPIClient\AccessTokenCredentials;

$username = 'your-username';
$password = 'your-password';
$baseURI = 'api.your-domain.pt';


$client = new APIClient($baseURI);
$options = [
    'verify' => false, // might need this if API uses self signed certificate
    'form_params' => [
        'key' => $username,
        'password' => $password
    ]
];

// authenticate on API to get token
$response = $client->post('/api/v1/auth/login', $options);
$loginResponseDecoded = json_decode($response->getBody()->getContents(), true);

$credentials = new AccessTokenCredentials($loginResponseDecoded['access_token']);
$client->setCredentials($credentials);

// e.g. Request types
$client->get();
$client->delete();
$client->patch();
$client->post();
$client->put();

如何获取访问令牌而不请求API的示例

// When using internally with other services can generate accessToken directly
$accessToken = $JWTManager->create($user);
$credentials = new AccessTokenCredentials($accessToken);

如何贡献

  • 分支项目
  • 将其克隆到您的机器上
  • 使用 composer install 安装依赖项
  • 打开一个Pull Request

如何测试

$ ./vendor/bin/phpunit

创建者

许可证

源代码许可协议为GPL v3。许可证可在此处找到。