Download the PHP package luk-z/php-api-token-auth without Composer
On this page you can find all versions of the php package luk-z/php-api-token-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download luk-z/php-api-token-auth
More information about luk-z/php-api-token-auth
Files in luk-z/php-api-token-auth
Package php-api-token-auth
Short Description Simple PHP REST API token-based authentication
License MIT
Homepage https://github.com/Luk-z/php-api-token-auth
Informations about the package php-api-token-auth
Php Api Token Authentication
This library is based on https://www.yiiframework.com/wiki/2568/jwt-authentication-tutorial
Install
Composer
Manual
Donwload ad extract source code from github, then include in you project:
Run test
Use in project
TODO
- https://phpstan.org/ see https://github.com/firebase/php-jwt/blob/main/.github/workflows/tests.yml
- changelog
- .editorconfig https://github.com/kreait/firebase-php https://github.com/cakephp/cakephp
PHP CS Fixer
To use correctly PHP CS Fixer copy settings.json-example
to settings.json
and insert absolute path of tools/php-cs-fixer/vendor/bin/php-cs-fixer
to php-cs-fixer.executablePath
Release
Repository is linked to packagist through (github web hook)[https://packagist.org/about#how-to-update-packages]. To push an update simply push a tag.
Functions
PATA::init()
Initialize the library passing dome configuration information.
Params: TODO
Returns: void
PATA::authenticate()
Take an access token and check if is valid/not expired
Params:
string
accessToken (required)bool
checkExpired (optional): default totrue
Returns:
-
Success response
-
Error response:
- Error codes:
- PATA_ERROR_AUTH_INVALID_TOKEN
- PATA_ERROR_AUTH_TOKEN_NOT_FOUND
- PATA_ERROR_AUTH_TOKEN_DUPLICATED
- PATA_ERROR_AUTH_TOKEN_EXPIRED
PATA::refreshToken()
Takes an access token and refresh token and try to refresh a new access token. If refreshToken not passed try to get from cookies
Params:
string
accessToken (required)string
refreshToken (required)
Returns:
-
Success response
-
Error response:
- Error codes:
- ... all error codes returned by Authenticate
- PATA_ERROR_REFRESH_TOKEN_INVALID - suggested response code=422
- PATA_ERROR_REFRESH_TOKEN_NOT_FOUND - suggested response code=401
- PATA_ERROR_REFRESH_TOKEN_EXPIRED - suggested response code=401
- PATA_ERROR_REFRESH_TOKEN_DIFFERENT_SID - suggested response code=401
- PATA_ERROR_REFRESH_TOKEN_DUPLICATED - suggested response code=401
PATA::activate()
Searches provided activation token and check validity then set user activated and set activation token expired
Params:
string
accessToken (required)
Returns:
-
Success response
-
Error response:
- Error codes:
- PATA_ERROR_ACTIVATE_TOKEN_NOTFOUND
- PATA_ERROR_ACTIVATE_DUPLICATED_TOKEN
- PATA_ERROR_ACTIVATE_TOKEN_USED
- PATA_ERROR_ACTIVATE_TOKEN_EXPIRED
- PATA_TOKEN_EXPIRATION_VALUE
- PATA_ERROR_ACTIVATE_TOKEN_DB_ERROR
PATA::registerUser()
Creates a user with given email and password then send activation email. If user already exists.
Params:
string
email (required)string
password (required)
Returns:
-
Success response
-
Error response:
- Error codes:
- PATA_ERROR_REGISTRATION_INVALID_EMAIL
- PATA_ERROR_REGISTRATION_INVALID_PASSWORD
- PATA_ERROR_REGISTRATION_EMAIL_EXITSTS
- PATA_ERROR_REGISTRATION_CREATE
PATA::loginUser()
Check provided credentials then create a user session with refresh token, access token and session id. If provided credentials are wrong or usr isn't activated return an error
Params:
string
email (required)string
password (required)
Returns:
-
Success response
-
Error response:
- Error codes:
- PATA_ERROR_LOGIN_INVALID_EMAIL
- PATA_ERROR_LOGIN_INVALID_PASSWORD
- PATA_ERROR_WRONG_EMAIL
- PATA_ERROR_WRONG_PASSWORD
- PATA_ERROR_USER_NOT_ACTIVE
PATA::logoutUser()
First executes authenticate() to check accessToken then delete user tokens associated to a specific sid
Params:
string
sid (required)string
accessToken (required)
Returns:
-
Success response
-
Error response:
- Error codes:
- ... all error codes returned by Authenticate
PATA::forgotPassword()
Check if email exists then send email with change password link (only if user is activated)
- check email is valid
- find active user
- find change password tokens
- if expired, delete it
- if not expired return error
Params:
string
email (required)
Returns:
-
Success response
-
Error response:
- Error codes:
- PATA_ERROR_FORGOT_PASSWORD_INVALID_EMAIL
- PATA_ERROR_FORGOT_PASSWORD_ALREADY_PRESENT
PATA::changePassword()
Check if password and token are valid then burn token and change password of the associated user (only if user is activated):
- check password is valid
- check token is valid and not expired
- check user is active
- check password is changed
- change password in db
- burn token
Params:
string
password (required)string
token (required) - change password token
Returns:
-
Success response
-
Error response:
- Error codes:
- PATA_ERROR_CHANGE_PASSWORD_INVALID_PASSWORD
- PATA_ERROR_CHANGE_PASSWORD_INVALID_TOKEN
- PATA_ERROR_CHANGE_PASSWORD_TOKEN_NOT_FOUND
- PATA_ERROR_CHANGE_PASSWORD_TOKEN_EXPIRED
- PATA_ERROR_CHANGE_PASSWORD_PASSWORD_NOT_CHANGED
- PATA_ERROR_CHANGE_PASSWORD_UPDATE_USER
Developing
Install php-cs-fixer
Usefull guides: