tfasoft / sdk
Telegram Factor Authentication PHP 库
dev-master
2023-04-20 12:26 UTC
Requires
- guzzlehttp/guzzle: ^7.4
Requires (Dev)
- phpunit/phpunit: ^9.5
- vlucas/phpdotenv: ^5.4
This package is auto-updated.
Last update: 2024-09-20 15:30:00 UTC
README
如果你在 PHP 应用程序中将 TFA 作为你的身份验证服务,你可以使用我们的库。
如何使用库
让我们快速回顾一下我们的步骤。
安装
你可以将其作为 composer 包安装
$ composer install tfasoft/sdk;
配置
用法
<?php // ... require_once __DIR__ . '/vendor/autoload.php'; // ... use TFASoft\TFA; // ... $tfa = new TFA("<access-token>"); // you can use $tfa->getAccessToken() to get the value you've set here $result = $tfa->authUser('<user-token>'); // ...
$result
将是一个包含两个 status
和 data
键的数组。$result["status"]
将是状态码。接下来,请参阅 下一部分 以查看 $result["data"]
的结构;
你也可以更改 API 的基本 URL
$tfa = new TFA("<access-token>", 'http://base-url/of/api/'); // ... $tfa->getBaseUrl(); // http://base-url/of/api/
输出结构
以下我们将深入了解它们(在 $result['data']
中可能的结果)。
{ "user": { "_id": "document id", "uid": "telegram user id", "token": "one time token. Every time become null", "createdAt": "when created", "updatedAt": "last update", "__v": 0 } }
一个是访问令牌错误。
{ "message": "User authentication token is not valid" }
另一个是用户令牌错误。
{ "message": "Admin access token is not valid" }
开发
如果你想贡献或更改代码
- 克隆项目
- 通过运行
$ composer install
安装依赖项 - 开始更改!
要测试您的更改,您可以在项目的根目录中创建一个 .env
文件
TEST_ACCESS_TOKEN="<access-token>"
TEST_USER_TOKEN="<user-token>"
然后运行 $ composer test
。