ottimis/phplibs

此包的最新版本(2.11.3)没有可用的许可证信息。

PHP 库


README

描述...

OAuth2.0

入门

导入所有内容并设置好带有 Slim 框架的 index.php 后,只需初始化一个新的 OAuth2 对象,添加必要的 GrantType,并调用生成各种端点的 api 即可。

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteCollectorProxy as RouteCollectorProxy;
use Slim\Exception\HttpNotFoundException as HttpNotFoundException;
use Slim\Factory\AppFactory;
use \ottimis\phplibs\OAuth2;

$app = AppFactory::create();
$oauth = new OAuth2();
$oauth->addGrantType($oauth::CLIENT_CREDENTIAL);

$oauth->api($app);

端点

所有端点都在 /oauth2 组下

以下是一个 authorize 调用的示例

https:///oauth2/authorize?response_type=code&client_id=testclient&state=xyz

此调用将返回用于通过 POST 请求获取 token 的必需 code 到返回 uri

curl -u testclient:testpass https:///oauth2/token -d 'grant_type=authorization_code&code=YOUR_CODE'

一旦获得 token,可以调用用于验证 token 和 scope 的端点

curl https:///oauth2/verify -d 'access_token=YOUR_TOKEN'

构建工具

日志记录器

入门

使用以下 SQL 查询创建库所需的表,并使用 composer 导入库

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for logs
-- ----------------------------
DROP TABLE IF EXISTS `logs`;
CREATE TABLE `logs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` int(11) DEFAULT NULL,
`stacktrace` text,
`note` text,
`code` varchar(10) DEFAULT NULL,
`datetime` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5397 DEFAULT CHARSET=latin1;

SET FOREIGN_KEY_CHECKS = 1;

<--------------------log_types------------------------------>

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for log_types
-- ----------------------------
DROP TABLE IF EXISTS `log_types`;
CREATE TABLE `log_types` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`log_type` varchar(15) DEFAULT NULL,
`color` varchar(7) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of log_types
-- ----------------------------
BEGIN;
INSERT INTO `log_types` VALUES (1, 'Log', '#259d00');
INSERT INTO `log_types` VALUES (2, 'Warning', '#d8a00d');
INSERT INTO `log_types` VALUES (3, 'Error', '#d81304');
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;
use \ottimis\phplibs\OAuth2;

作者

  • Ottimis Group