PHP code example of gud3 / yii2-rest-auth

1. Go to this page and download the library: Download gud3/yii2-rest-auth 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/ */

    

gud3 / yii2-rest-auth example snippets


public static function findIdentityByAccessToken($id, $type = null)
{
    return static::find()->where(['id' => $id])->one() || false;
}

public function behaviors()
{
    $behaviors = parent::behaviors();
    
    $auth = ['index'];
    //$auth = ['index', 'update', 'create', 'etc..'];
    $behaviors['authenticator']['class'] = \gud3\restAuth\CheckToken::className();
    $behaviors['authenticator']['only'] = $auth;

    return $behaviors;
}

public function behaviors()
{
    $behaviors = parent::behaviors();
    
    $auth = [];
    
    if (\gud3\restAuth\CheckToken::isAuth()) {
        array_push($auth, 'index', 'create');
    }
        
    $behaviors['authenticator']['class'] = \gud3\restAuth\CheckToken::className();
    $behaviors['authenticator']['only'] = $auth;
    
    return $behaviors;
}

'components' => [
    'cache' => [
        'class' => 'yii\redis\Cache',
    ],
]