This is about the simple authentication API in PHP
- Clone this repository via gitcommand
git clone https://github.com/open-source-contributions/simple-auth-php- Docker image build
docker build -t simple_auth_php .- Docker container executing
docker run -p 5000:80 -d simple_auth_phpWe assume developers use the Guzzle, HTTP client to request this auth API.
- LoginAction API, it's- loginaction request.
use GuzzleHttp\Client;
$client = new Client();
$formParams = [
    'form_params' => [
        'action' => 'login',
        'account' => 'the_account',
        'password' => 'the_password',
    ],
];
$response = $client->request('POST', 'http://localhost:5000', $formParams);
$response = (string) $response->getBody();
$response = json_decode($response, true);
// output: {"result":"Auth is successful.","token":"your_user_token"}- LogoutAction API, it's- logoutaction request.
use GuzzleHttp\Client;
$client = new Client();
$formParams = [
    'form_params' => [
        'action' => 'logout',
        'account' => 'test',
        'token' => 'your_user_token',
    ],
];
$response = $client->request('POST', 'http://localhost:5000', $formParams);
$response = (string) $response->getBody();
$response = json_decode($response, true);
// output: {"result":"Logout is done."}- StatusAction API, it's- statusaction request.
use GuzzleHttp\Client;
$client = new Client();
$formParams = [
    'form_params' => [
        'action' => 'status',
        'account' => 'test',
        'token' => 'your_user_token',
    ],
];
$response = $client->request('POST', 'http://localhost:5000', $formParams);
$response = (string) $response->getBody();
$response = json_decode($response, true);
// output: {"result":"Token is expired. It should be logout."}
// or
// output: {"result":"Token is live."}