elementworks / jwt-tokens
Create JWT tokens
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Type:craft-plugin
pkg:composer/elementworks/jwt-tokens
Requires
- craftcms/cms: ^3.0.0
- firebase/php-jwt: ^6.10.0
README
Create JWT Tokens in Twig.
Requirements
This plugin requires Craft CMS 3.0.0-beta.23 or later.
Installation
To install the plugin, follow these instructions.
- 
Open your terminal and go to your Craft project: cd /path/to/project
- 
Then tell Composer to load the plugin: composer require elementworks/jwt-tokens
- 
In the Control Panel, go to Settings → Plugins and click the “Install” button for JWT Tokens. 
Settings
The only setting is a signing secret. It is recommended to set this using an environment variable.
How to create a JWT Token
First, create a payload as a Twig hash (associative array).
Next, pass this into the Twig function, along with the algorithm (e.g. 'HS256') to create the token:
{% set payload = {
   'name': 'John Doe',
   'company': 'Google',
} %}
{% set token = craft.jwtTokens.createToken(payload, 'HS256') %}
Brought to you by Steve Rowling