How to redirect to the login page with BjyAuthorize

落花浮王杯 提交于 2019-12-01 20:32:40

Finally I got it.

With version 1.2.* of BjyAuthorize, you simply add in config/autoload/bjyauthorize.global.php :

return array(
    'bjyauthorize' => array(
        'unauthorized_strategy' => 'BjyAuthorize\View\RedirectionStrategy',
//      [...]
    ),
);

And it will redirect you to the route configured in vendor/bjyoungblood/bjy-authorize/src/BjyAuthorize/View/RedirectionStrategy.php

Check this UnauthorizedStrategy class by Rob Allen: https://gist.github.com/akrabat/3783912 When using this class you have to configure BjyAuthorize to use it, like this:

return array(
    'bjyauthorize' => array(
        'unauthorized_strategy' => 'Application\View\UnauthorizedStrategy',
    ),
);

Edit: Don't forget to add the relevant service manager config to allow the service manager to instantiate the UnauthorizedStrategy object:

'service_manager' => array(
'invokables' => array(
            'Application\View\UnauthorizedStrategy' => 'Application\View\UnauthorizedStrategy',
        ),

I'm also trying and I came across this page: https://github.com/bjyoungblood/BjyAuthorize/issues/24

This way, you can extend the UnauthorizedStrategy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!