PHP code example of luk-z / php-api-token-auth

1. Go to this page and download the library: Download luk-z/php-api-token-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

luk-z / php-api-token-auth example snippets



[
    "result" => true,
    "data" => ["sid" => string] // user session id
]

[
    "result" => false,
    "error" => [
        "message" => string,
        "code" => string,
        "fields" => array,
    ]
]

[
    "result" => true,
    "data" => [
        "sid" => string,
        "refreshToken" => string,
        "accessToken" => string,
        "debug" => [
            "setCookieResult" => string,
            "tokenInsertResult" => string,
            "deleteTokensResult" => string,
        ],
    ]
]

[
    "result" => false,
    "error" => [
        "message" => string,
        "code" => string,
        "fields" => array,
    ],
    "responseCode" => string, // suggested response code to return by endpoints
]

[
    "result" => true,
    "data" => [
        "queryResult" => int, // affected row (should be 1)
        "userId" => int
    ]
]

[
    "result" => false,
    "error" => [
        "message" => string,
        "code" => string,
    ],
]

[
    "result" => true,
    "data" => [
        "id" => int, // userId
        "shouldSendActivationEmail" => bool, // whether an activation email should be sent
        "activationToken" => "xxxxx", // user token for account activation
    ]
]

[
    "result" => false,
    "error" => [
        "message" => string,
        "code" => string,
        "fields" => ["id"=>int], // userId
    ],
]

[
    "result" => true,
    "data"=>[
        "user" => array,
        "accessToken" => string,
        "sid" => string,
        "debug" => [
            "rtResult" => bool, // whether the set_cookie has succedeed
            "tokenInsertResult" => bool // whether the token is succesfully created in the database
        ],
    ]
]

[
    "result" => false,
    "error" => [
        "message" => string,
        "code" => string,
    ],
]

[
    "result" => true,
    "data" => [
        "queryResult" => int, // number of user session tokens deleted
    ]
]

[
    "result" => false,
    "error" => [
        "message" => string,
        "code" => string,
    ],
]

[
    "result" => true,
    "data"=>[
        "changePasswordToken" => string,
        "shouldSendChangePasswordEmail" => string,
        "queryResult" => int,
    ]
]

[
    "result" => false,
    "error" => [
        "message" => string,
        "code" => string,
    ],
    "secondsLeft" => int // only if a valid token is already present, indicates the remaining seconds till token expiration
]

[
    "result" => true,
    "data" => [
        "queryResult" => boolean, // whether the user password is modified correctly
        "currentTokenDeleted" => int, // result of deleting current change password token (should be always 1)
        "accessTokenDeleted" => int, // number of access token deleted
        "refreshTokenDeleted" => int, // number of refresh token deleted
        "email" => int, // email of the current user
        "userId" => int, // id of the current user
    ]
]

[
    "result" => false,
    "error" => [
        "message" => string,
        "code" => string,
    ],
]
shell
composer