staffbase / plugins-sdk-php
Staffbase PHP SDK 插件库。
Requires
- php: ^7.4 || ^8.0
- lcobucci/jwt: ^4.1
Requires (Dev)
- cvuorinen/phpdoc-markdown-public: ^0.2.0
- phpseclib/phpseclib: ^2.0
- phpunit/phpunit: ^9.0
- dev-master
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.0
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.0
- 1.0.0-rc2
- 1.0.0-rc1
- dev-dependabot/composer/lcobucci/jwt-tw-4.1or-tw-5.0
- dev-dependabot/composer/phpseclib/phpseclib-tw-2.0or-tw-3.0
- dev-NFS-1777-header-jwt-token
- dev-chore-php8-update
- dev-Update-To-Github-Actions
- dev-cctech-added-email-username-to-ssodata
- dev-allow-session-parameters-as-body-parameter
- dev-NFS-616-session-deletion-fix
This package is auto-updated.
Last update: 2024-09-24 07:17:06 UTC
README
如果您正在为您的 Staffbase 应用开发自己的插件,我们将在 https://developers.staffbase.com/guide/customplugin-overview/ 中描述插件的身份验证流程。虽然这份文档仅涵盖了插件接口(即所谓的插件单点登录)的概念性内容,但我们希望提供一个库来帮助您更快地开发 Staffbase 的第一个插件。此 SDK 为 PHP 提供了解析和验证提供的令牌的基本功能。
安装
我们通过 Composer (https://packagist.org.cn/packages/staffbase/plugins-sdk-php) 提供 Plugin SDK。因此,您只需使用 Composer 进行安装
composer require staffbase/plugins-sdk-php
依赖关系
依赖关系也由 Composer 管理。当使用此存储库时,请注意以下依赖关系(参看 composer.json)
- php: ^7.4.0 || ^8.0
- lcobucci/jwt: ^4.1
API 参考
有关此 SDK 的 API 参考,请参阅 文档。
代码示例
您可以从接收到的 jwt 创建一个令牌。
use Exception; use Staffbase\plugins\sdk\SSOToken; try { $appSecret = 'abcdef012345='; // the public key received from Staffbase. $sso = new SSOToken($appSecret, $_GET['jwt']); print "Hello again ". $sso->getFullName(); } catch (Exception $e) { print "Sorry we could not authenticate You."; exit; }
为了方便且安全地管理多个实例,我们提供了一个便利类,该类封装了会话。`PluginSession` 类具有与 `SSOToken` 相同的数据接口。它还提供了将自定义会话保存处理程序作为 `__construct` 方法的可选第三个参数的途径。`PluginSession` 将自动处理读取 URL 参数和在会话中保存 SSO 信息,以便在令牌无效后进行后续请求。
use Exception; use Staffbase\plugins\sdk\PluginSession; try { $pluginId = 'weatherplugin'; // the id you received from Staffbase. $appSecret = 'abcdef012345='; // the public key received from Staffbase. $session = new PluginSession($pluginId, $appSecret); print "Hello again ". $PluginSession->getFullName(). ', '. $PluginSession->getSessionVar('message'); } catch (Exception $e) { print "Sorry we could not authenticate You."; exit; }
远程调用
在版本 1.2.0 中,我们引入了远程调用的概念。当 Staffbase 应用需要通知插件有关可能相关的某些事件时,就会发生远程调用。事件可以是:插件实例被删除或用户应该注销。目前我们只支持实例删除调用。您可以在 `RemoteCall` 命名空间中找到所有受支持的调用。
use Staffbase\plugins\sdk\RemoteCall\AbstractRemoteCallHandler; use Staffbase\plugins\sdk\RemoteCall\DeleteInstanceCallHandlerInterface; // create a call handler which can have multiple call interfaces implemented class RemoteCallHandler extends AbstractRemoteCallHandler implements DeleteInstanceCallHandlerInterface { private $db; public function __construct($db) { $this->db = $db; } public function deleteInstance($instanceId) { $result = $this->db->posts->deleteByInstance($instanceId); return $result !== false; } } // pass it to the PluginSession on construction as the last parameter $remoteCallHandler = new RemoteCallHandler($db); $session = new PluginSession(PLUGIN_ID, $secret, $sessionHandler, null, $remoteCallHandler); /* Unreachable code in a delete call follows */ ...
请注意,远程调用将通过实现 `RemoteCallInterface` 的退出函数或通过警告强制退出。这是因为实际上在调用后没有会话可以构建。
贡献
- 分叉它
- 创建一个分支
git checkout -b feature-description - 将您的姓名放入 authors.txt 中
- 提交您的更改
git commit -am "Added ...." - 将分支推送到远程仓库
git push origin feature-description - 打开一个拉取请求
运行测试
要运行测试,请在根目录中执行简单的 # composer test 命令。请参阅 composer.json 了解当前使用的 phpunit 版本。
许可协议
版权所有 2017-2022 Staffbase GmbH。
在 Apache 许可证 2.0 版下授权: https://apache.ac.cn/licenses/LICENSE-2.0