Skip to content

Instantly share code, notes, and snippets.

@ydatech
Created October 9, 2016 11:29
Show Gist options
  • Select an option

  • Save ydatech/1f58fdbface61816fe3f8ece3a49280b to your computer and use it in GitHub Desktop.

Select an option

Save ydatech/1f58fdbface61816fe3f8ece3a49280b to your computer and use it in GitHub Desktop.
ActiveController
<?php
namespace app\controllers;
use yii\filters\Cors;
use yii\filters\auth\HttpBearerAuth;
class ActiveController extends \yii\rest\ActiveController{
// Override behaviors() untuk menambahkan \yii\filters\Cors
public function behaviors(){
$behaviors = parent::behaviors();
// unset / hapus authenticator
unset($behaviors['authenticator']);
// tambahkan cors filter
$behaviors['corsFilter'] = [
'class' => Cors::className(),
];
//tambahkan HttpBearerAuth untuk autentikasi berbasis token
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::className(),
'except'=>['options']
];
return $behaviors;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment