I am working on API in Yii2, where I need to use different authentication methods for different actions.
How can I set CompositeAuth for action1, action2 and action3, and HttpBasicAuth for action4 and action5?
public function behaviors()
{
return [
'basicAuth' => [
'class' => \yii\filters\auth\HttpBasicAuth::className(),
'auth' => function ($username, $password) {
$user = User::find()->where(['username' => $username])->one();
if ($user->verifyPassword($password)) {
return $user;
}
return null;
},
],
];
}