Interface luya\rest\UserBehaviorInterface

Implemented byluya\admin\apis\ApiUserController, luya\admin\apis\CommonController, luya\admin\apis\ConfigController, luya\admin\apis\EffectController, luya\admin\apis\FilterController, luya\admin\apis\GroupController, luya\admin\apis\LangController, luya\admin\apis\LoggerController, luya\admin\apis\MenuController, luya\admin\apis\NgrestLogController, luya\admin\apis\PropertyController, luya\admin\apis\ProxyBuildController, luya\admin\apis\ProxyMachineController, luya\admin\apis\QueueLogController, luya\admin\apis\QueueLogErrorController, luya\admin\apis\SearchController, luya\admin\apis\StorageController, luya\admin\apis\StorageImageController, luya\admin\apis\TagController, luya\admin\apis\TimestampController, luya\admin\apis\UserController, luya\admin\base\RestActiveController, luya\admin\base\RestController, luya\admin\ngrest\base\Api, luya\cms\admin\apis\AdminController, luya\cms\admin\apis\BlockController, luya\cms\admin\apis\BlockgroupController, luya\cms\admin\apis\LayoutController, luya\cms\admin\apis\LogController, luya\cms\admin\apis\MenuController, luya\cms\admin\apis\NavContainerController, luya\cms\admin\apis\NavController, luya\cms\admin\apis\NavItemBlockController, luya\cms\admin\apis\NavItemController, luya\cms\admin\apis\NavItemPageBlockItemController, luya\cms\admin\apis\NavItemPageController, luya\cms\admin\apis\RedirectController, luya\cms\admin\apis\ThemeController, luya\cms\admin\apis\WebsiteController
Available since version1.0.0
Source Code https://github.com/luyadev/luya/blob/master/core/rest/UserBehaviorInterface.php

REST User Behavior Interface.

The iplementation of the UserBeavhiorInterface should come along with the {{luya\traits\RestBehaviorsTrait}}.

An example integration:

class MyRestController extends \luya\rest\Controller implements \luya\rest\UserBehaviorInterface
{
    use \luya\traits\RestBehaviorTrait; // Use is already done by the \luya\rest\Controller class.

    public function userAuthClass()
    {
        return Yii::$app->user;
    }

    // Is action is now secured by the `app\models\User` model.
    public function actionIndex()
    {
        return ['foo' => 'bar'];
    }
}

Public Methods

Hide inherited methods

Method Description Defined By
userAuthClass() Returns the class object for the authentication of the rest api. If the return value is false the authentication is disabled for the whole rest controller. luya\rest\UserBehaviorInterface

Method Details

Hide inherited methods

userAuthClass() public abstract method

Returns the class object for the authentication of the rest api. If the return value is false the authentication is disabled for the whole rest controller.

return a user object (based on {{yii\web\User}}):

return Yii::$app->adminuser;

return a class string will create a new object from this class string:

return \luya\admin\components\AdminUser::class;

return false will disabled the authentication proccess for this rest controller:

return false;

It can also be an array with configurations:

return [
    'class' => 'app\models\User',
    'property1' => 'value',
];
public abstract boolean|string|yii\web\User userAuthClass ( )
return boolean|string|yii\web\User

If false is returned the protection is disabled, if a string is provided this will be threated as className to create the User object.

                public function userAuthClass();