erwane/cakephp-token

Easy use token in CakePHP 4

Installs: 262

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 1

Open Issues: 0

Type:cakephp-plugin

2.0.1 2021-01-18 15:11 UTC

This package is auto-updated.

Last update: 2021-02-18 15:33:13 UTC


README

Description

This is a really "simple to use" cakephp 4 plugin for generating and reading temporaries tokens

Installation

composer require erwane/cakephp-token:^2.0
bin/cake migrations migrate -p Token

Usage

Generate a token

/**
 * 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
 * @return string            The token id
 */

$myNewTokenId = \Token\Token::generate(array $content, $expire);

Get token

// 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

/**
 * 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