Telegram Factor Authentication - PHP SDK
PHP SDK document is in docs.tfasoft.com
If you are using TFA as your authentication service in your PHP applications, you can use our library.
How to use the library
So, let's have a quick review of our steps.
Installation
You can install this as a composer package:
$ composer install tfasoft/sdk;
Configuration
Usage:
<?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>');
// ...
The $result
will be an array with two status
and data
keys.
$result["status"]
will be the status code.
And go to the next part to see structure of $result["data"]
;
Also you can change the base URL of the API:
$tfa = new TFA("<access-token>", 'http://base-url/of/api/');
// ...
$tfa->getBaseUrl(); // http://base-url/of/api/
Output structure
Here let's know about them in deep (possible results in $result['data']
).
-
200
{
"user": {
"_id": "document id",
"uid": "telegram user id",
"token": "one time token. Every time become null",
"createdAt": "when created",
"updatedAt": "last update",
"__v": 0
}
}
-
401
One is access token is wrong.
{
"message": "User authentication token is not valid"
}
Another is when user token is wrong.
{
"message": "Admin access token is not valid"
}
Development
If you want to contribute or change the code:
- Clone the project
- Install dependencies by running
$ composer install
- Start changing!
To test your changes, you can create a .env
file in root directory of project:
TEST_ACCESS_TOKEN="<access-token>"
TEST_USER_TOKEN="<user-token>"
and then run $ composer test
.