https://github.com/dmstr/yii2-token-manager
https://github.com/dmstr/yii2-token-manager
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/dmstr/yii2-token-manager
- Owner: dmstr
- Created: 2022-12-21T13:16:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-04-28T15:31:09.000Z (about 1 year ago)
- Last Synced: 2025-04-28T16:25:10.006Z (about 1 year ago)
- Language: PHP
- Size: 36.1 KB
- Stars: 4
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Token Manager
A token manager for jwt tokens
## Installation
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
composer require dmstr/yii2-token-manager
```
or add
```
"dmstr/yii2-token-manager": "dev-master"
```
to the require section of your `composer.json` file.
## Configuration
Add the component to your config
```php
use dmstr\tokenManager\components\TokenManager;
return [
'components' => [
'tokenManager' => [
'class' => TokenManager::class
]
]
];
```
## Usage
Once the extension is installed and configurated, simply use it in your code by:
For more infos about Yii2 and JWT check out [lcobucci/jwt](https://github.com/lcobucci/jwt)
```php
use dmstr\tokenManager\exceptions\LoadTokenException;
$token = ...; // valid Jwt token
Yii::$app->tokenManager->setToken($token);
try {
$roles = Yii::$app->tokenManager->getRoles();
} catch (LoadTokenException $exception) {
// ...
}
```