juanchosl/tokenizer
最新稳定版本:1.0.3
Composer 安装命令:
composer require juanchosl/tokenizer
包简介
A small collection of encoder/decoder Token for authentication
README 文档
README
Description
A small collection of encoder/decoder Token for authentication
This is a test project in order to check how works the composer installation directly from GitHub
Install
composer require juanchosl/tokenizer
How use it
Entities
The system use a CredentialInterface as DTO, a simple object with username and password
All credentials needs to be pushed into a CredentialsInterface collection, a sequence of available usersto compare. We provide a simple Collection in order to push a few users, but is importante that you create your own implementation in order to search usrs into database, as usual
In a login request, you needs to ensure the username+password validation before create a token
Use a concret Tokenizer
For create a token
$options = [ JwtToken::OPTION_ISSUER => $_ENV['CYPHER_KEY'], JwtToken::OPTION_AUDIENCE => 'Restricted area' ]; $tokenizer = new JuanchoSL\Tokenizer\Repositories\JwtToken($options); $token = $tokenizer->encode(new Credential($username, $password));
For decode a token
$user_data = $tokenizer->decode($token);
For a check a token with a previously retrieved user
$tokenizer->check($db_data, $token):
Use the provided service
For create a token
$options = [ JwtToken::OPTION_ISSUER => $_ENV['CYPHER_KEY'], JwtToken::OPTION_AUDIENCE => 'Restricted area' ]; $tokenizer = new JuanchoSL\Tokenizer\Repositories\JwtToken($options); $service = new Authentication($tokenizer, new Credentials); $service->authenticateByCredential($credential); return $service->generateToken($credential);
For decode a token
$options = [ JwtToken::OPTION_ISSUER => $_ENV['CYPHER_KEY'], JwtToken::OPTION_AUDIENCE => 'Restricted area' ]; $tokenizer = new JuanchoSL\Tokenizer\Repositories\JwtToken($options); $service = new Authentication($tokenizer, new Credentials); return $service->->authenticateByToken($token);
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-27