I'd like to add an API to an existing app using the Auth component and Form scheme authentication, using Basic authentication.
This is the configuration I think I would like to have, but I'm not sure if settings can be entered in a per-scheme way.
Alternatively, is there a way to change Auth component settings based on the route? For example use Form based unless the url extension is json, in which case use Basic?
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
],
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
],
'storage' => 'Session',
'unauthorizedRedirect' => $this->referer()
],
'Basic' => [
'fields' => [
'username' => 'username',
'password' => 'api_key'
],
'storage' => 'Memory',
'unauthorizedRedirect' => false
]
],
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
],
]);