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