https://github.com/erwane/cakephp-token
Generate and Manage token in CakePHP 3 and 4
https://github.com/erwane/cakephp-token
cakephp
Last synced: 8 months ago
JSON representation
Generate and Manage token in CakePHP 3 and 4
- Host: GitHub
- URL: https://github.com/erwane/cakephp-token
- Owner: Erwane
- License: mit
- Created: 2016-07-20T16:07:01.000Z (over 9 years ago)
- Default Branch: v2.x
- Last Pushed: 2023-11-14T15:59:44.000Z (almost 2 years ago)
- Last Synced: 2024-03-14T19:54:20.044Z (over 1 year ago)
- Topics: cakephp
- Language: PHP
- Homepage:
- Size: 59.6 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CakePHP 4 Token plugin
## Description
This is a really "simple to use" cakephp 4 plugin for generating and reading temporaries tokens
## Installation
```bash
composer require erwane/cakephp-token:^2.0
bin/cake migrations migrate -p Token
```
## Usage
### Generate a token
```php
/**
* Create a token with data and return the id
* @param array $content an array of custom data
* @param string $expire expire exprimed in '+6 days +2 hours' format
* @param int $length Token length
* @return string The token id
*/
$myNewTokenId = \Token\Token::generate(array $content, $expire, 8);
```
### Get token
```php
// return null (expired or not found) or Token entity
$token = \Token\Token::get($tokenId);
```
### Delete token
Tokens deletion can be ignored, they will be destroyed on expire, but sometime you need to delete one token immediately
```php
/**
* Delete token from id or entity
*
* @param \Token\Model\Entity\Token|string $token Token entity or id
* @return bool True if token was deleted
*/
$result = \Token\Token::delete($token);
```
### Auto cleaning
Each time a token is read, expired tokens are pruned