title: Yii2 REST Simplify BasicAuth
body: <p>I'm impressed with how simple it was to create a REST api in Yii2.  However, i'm having a little trouble understanding the Basic Authentication.  My needs are utterly simple and i'd like my solution to follow suit.</p>
  
  <p>I need Basic token authentication here.  I'm not even against hardcoding it for now, but here's what i've done thus far.</p>
  
  <p>I have database table to hold my singular token  ApiAccess(id, access_token)</p>
  
  <p><strong>ApiAccess.php - Model</strong> - NOTE: IDE shows syntax error on this first line</p>
  
  <pre><code> class ApiAccess extends base\ApiAccessBase implements IdentityInterface
   {
     public static function findIdentityByAccessToken($token, $type = null)
     {
       return static::findOne(['access_token' =&gt; $token]);
     }
   }
  </code></pre>
  
  <p><strong>Module.php</strong> - in init() function</p>
  
  <pre><code> \Yii::$app-&gt;user-&gt;enableSession = false;
  </code></pre>
  
  <p>I made an ApiController that each subsequent noun extends</p>
  
  <p><strong>ApiController.php</strong></p>
  
  <pre><code> use yii\rest\ActiveController;
   use yii\filters\auth\HttpBasicAuth;
   use app\models\db\ApiAccess;
  
   class ApiController extends ActiveController
   {
     public function behaviors()
     {
        $behaviors = parent::behaviors();
        $behaviors['authenticator'] = [
          'class' =&gt; HttpBasicAuth::className(),
        ];
       return $behaviors;
     }
   }
  </code></pre>
  
  <p>As it stands, accessing an api endpoint in the browser prompts for a username and password.  Request via REST Client displays access error.</p>
  
  <p><strong>How do I properly tie HttpBasicAuth to my ApiAccess model?</strong></p>
  
  <p>OR</p>
  
  <p><strong>How do I hardcode an api access token?</strong>  (First option is obviously best)</p>