This is about the simple authentication API in PHP
- Clone this repository via
git
command
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_php
We assume developers use the Guzzle, HTTP client
to request this auth API.
Login
Action API, it'slogin
action 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"}
Logout
Action API, it'slogout
action 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."}
Status
Action API, it'sstatus
action 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."}