PHP code example of thamtech / yii2-jws

1. Go to this page and download the library: Download thamtech/yii2-jws library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thamtech / yii2-jws example snippets


    return [
      'components' => [
        'jwsManager' => [
          'class' => 'thamtech\jws\components\JwsManager',
          'pubkey' => '@app/config/keys/jws/public.pem',
          'pvtkey' => '@app/config/keys/jws/private.pem',
          
          // The settings below are optional. Defaults will be used if not set here.
          //'encoder' => 'Namshi\JOSE\Base64\Base64UrlSafeEncoder',
          //'exp' => '1 hour',
          //'alg' => 'RS256',
          //'jwsClass' => 'Namshi\JOSE\SimpleJWS',
        ],
      ]
    ]
    

$payload = [
  "user_id": 23,
  "foo": "bar",
];
$tokenString = Yii::$app->jwsManager->newToken($payload);

$token = Yii::$app->jwsManager->load($tokenString);
$result = Yii::$app->jwsManager->verify($token);

$token = Yii::$app->jwsManager->load($tokenString);
$result = Yii::$app->jwsManager->isValid($token);