Created
October 9, 2016 11:29
-
-
Save ydatech/1f58fdbface61816fe3f8ece3a49280b to your computer and use it in GitHub Desktop.
ActiveController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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