configure Auth component differently per scheme

时间:2019-04-16 23:37:44

标签: authentication cakephp cakephp-3.0

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'
    ],
]);

0 个答案:

没有答案