1. Go to this page and download the library: Download msheng/yii2-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/ */
// ...
use yii\filters\auth\CompositeAuth;
use yii\filters\auth\HttpBearerAuth;
class BearerAuthController extends \yii\rest\ActiveController
{
public function behaviors()
{
return array_merge(parent::behaviors(), [
'authenticator' => [
'class' => CompositeAuth::className(),
'authMethods' => [HttpBearerAuth::className(),],
]
]);
}
}
// ...
use yii\db\ActiveRecord;
use yii\web\IdentityInterface
class User extends ActiveRecord implements IdentityInterface
{
// Use the trait in your User model
use \msheng\JWT\UserTrait;
}
// $user is an User object
$token = $user->getJwt()
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.