Authentication
In this recipe will have the authentication model set up.
Getting ready
Repeat all steps from the Creating a REST server recipe in Getting ready and How to do it sections.
How to do it...
Modify
@app/controllers/FilmController
to the following:<?php namespace app\controllers; use app\models\User; use Yii; use yii\helpers\ArrayHelper; use yii\rest\ActiveController; use yii\filters\auth\HttpBasicAuth; class FilmController extends ActiveController { public $modelClass = 'app\models\Film'; public function behaviors() { return ArrayHelper::merge(parent::behaviors(),[ 'authenticator' => [ 'authMethods' => [ 'basicAuth' => [ 'class' =>HttpBasicAuth::className(), 'auth' => function ($username,$password) { $user =User::findByUsername($username); ...