定制 securibox/cloudagents 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

securibox/cloudagents

Composer 安装命令:

composer require securibox/cloudagents

包简介

API wrapper for Securibox Cloud Agents.

README 文档

README

Packagist Version

A PHP client library for the Securibox Cloud Agents API

Install Package

Securibox Cloud Agent PHP wrapper is installed via Composer. Simply run the following command:

composer require securibox/cloudagents

Alternative: Install package from zip

If you are not using Composer, simply download and install the latest packaged release of the library as a zip.

Authentication

In order to secure the Securibox Cloud Agents API, three mechanisms have been implemented. Here is a brief overview of the three mechanisms as well as code snippets to help you integrate the correct mechanism in order to call the APIs.

Basic API Authentication w/ TLS

Basic API authentication is the easiest of the three to implement offering the lowest security options of the common protocols. This mechanism is usually advised for testing purposes in order to test the APIs and only requires Securibox to provide a username and password.

use Securibox\CloudAgents\Documents\ApiClient;

$client = ApiClient::AuthenticationBasic("username", "password");

SSL Client Certificate Authentication

The SSL client certification is a mechanism allowing your application to authenticate itself with the Securibox Cloud Agents (SCA) servers. In this case, your application will send its SSL certificate after verifing the SCA server identity. Then, the client and server use both certificates to generate a unique key used to sign requests sent between them.

This kind of authentication is implemented when the customer call your servers that will then call the Securibox Cloud Agents API.

In order to use this type of authentication, Securibox will provide a PEM certificate file containing a passphrase protected private key and a public key.

use Securibox\CloudAgents\Documents\ApiClient;

$client = ApiClient::SslClientCertificate("C:\Path\to\PEM Certificate", "PEM pass phrase");

JSON Web Token Authentication

JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a public/private key pair using RS256 (RSA PKCS#1 signature with SHA-256).

This kind of authentication is implemented when the customer calls directly the Securibox Cloud Agents API together with cross-origin resource sharing (CORS).

In order to use this type of authentication, Securibox will provide a passphrase protected RSA private key in PEM file (.pem).

use Securibox\CloudAgents\Documents\ApiClient;

$client = ApiClient::Jwt("C:\Path\to\PEM private key", "PEM pass phrase");

Getting started

The following is the minimum needed code to list all agent details and fields:

<?php 
// If you are using Composer (recommended)
require 'vendor/autoload.php';
use Securibox\CloudAgents\Documents\ApiClient;
use Securibox\CloudAgents\Documents\Entities;

// If you are not using Composer
// require("path/to/cloudagents-php/src/autoload.php");

$client = ApiClient::AuthenticationBasic("Basic Username", "Basic Password");
$agents = $client->GetAgents();
foreach($agents as $agent){
    print("\n\n\n------ Agent Details ------\n");
    print("ID: ".$agent->id."\n");
    print("Name: ".$agent->name."\n");
    print("Periodicity: ".$agent->agentPeriodicity."\n");
    print("Current Status: ".$agent->agentCurrentState."\n");
    print("Category: ".$agent->category."\n");
    foreach($agent->fields as $field){
        print("   Field[". $field->position ."]: ".$field->name."\n");
    }
}

The following code is the minimum code needed to configure an agents and launch a synchronization:

<?php
// If you are using Composer (recommended)
require 'vendor/autoload.php';
use Securibox\CloudAgents\Documents\ApiClient;
use Securibox\CloudAgents\Documents\Entities;

// If you are not using Composer
// require("path/to/cloudagents-php/src/autoload.php");

//Configure account properties
$account = new Entities\Account();
$account->agentId = '93fddb673a2d4fb49406f21a5937dc90';
$account->customerAccountId = 'UNITTESTS_PHP_SDK';
$account->customerUserId = 'UNITTESTS_PHP_SDK_UID';
$account->name = 'Test Account SDK 1';
$account->credentials = array();

//Configure credentials
$username = new Entities\Credential();
$username->position = 0;
$username->value = 'username@test.com';

//Configure credentials
$password = new Entities\Credential();
$password->position = 1;
$password->value = '###password###';

array_push($account->credentials, $username, $password);

//Setup client
$client = new ApiClient::AuthenticationBasic("Basic Username", "Basic Password");

//Create the account which automatically launches a synchronization
$returnedAccount = $client->CreateAccount($account);

//Let's wait until the synchronization has reached a final status
$synchronization = $client->GetLastSynchronizationByAccount($returnedAccount->customerAccountId);
while($synchronization->synchronizationState != "PendingAcknowledgement" &&
      $synchronization->synchronizationState != "Completed" &&
      $synchronization->synchronizationState != "ReportFailed"){
        sleep(5);
        $synchronization = $client->GetLastSynchronizationByAccount($returnedAccount->customerAccountId);
}

//Let's get the newly downloaded documents and save them locally
$documents = $client->GetDocumentsByAccount($account->customerAccountId, 'true','true');
$receivedFiles = array();
foreach($documents as $document){
    $file = fopen("C:\\Temp\\".$document->name, "wb");
    $content =  base64_decode($document->base64Content);
    fwrite($file, $content);
    fclose($file);
    array_push($receivedFiles, $document->id);   
}
$client->AcknowledgeSynchronizationForAccount($account->customerAccountId, $receivedFiles, array());

Webview url

In order to use the webview and avoid having to implement the APIs to list and configure accounts, a webview has been developped. In this webview, a customer can:

  • Browse and search all agents
  • Have quick access to predefined favorite agents
  • List the configured agents
  • Configure, modify or delete an agent account
  • See the list of synchronizations for each account

To use the webview, activate it in the CloudAgents backoffice and use the provided PEM private key to sign the token.

The webview accepts the following url arguments:

Example:

https://sca-webview.azurewebsites.net?token={token}&callback={callback_url}&state={stateData}
https://sca-webview.azurewebsites.net?token={token}&callback={callback_url}&state={stateData}&lang=en-us

For examples in php to generate the token, please refer to the test.

License

GNU GPL

securibox/cloudagents 适用场景与选型建议

securibox/cloudagents 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.29k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 08 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cloud」 「connectors」 「agents」 「securibox」 「sca」 「sbx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 securibox/cloudagents 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 securibox/cloudagents 我们能提供哪些服务?
定制开发 / 二次开发

基于 securibox/cloudagents 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8.29k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 34
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2017-08-09