PHP code example of xzag / yii3-jwt
1. Go to this page and download the library: Download xzag/yii3-jwt 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/ */
xzag / yii3-jwt example snippets
// ...
use yii\web\filters\auth\HttpBearerAuth;
use Yiisoft\Yii\Rest\ActiveController;
class BearerAuthController extends ActiveController
{
public function behaviors()
{
return array_merge(parent::behaviors(), [
'bearerAuth' => [
'class' => HttpBearerAuth::class
]
]);
}
}
// ...
use yii\activerecord\ActiveRecord;
use yii\web\IdentityInterface;
class User extends ActiveRecord implements IdentityInterface
{
// Use the trait in your User model
use xzag\JWT\UserTrait;
// Override this method
protected static function getSecretKey()
{
return 'someSecretKey';
}
// And this one if you wish
protected static function getHeaderToken()
{
return [];
}
// ...
}