How to redirect to the login page with BjyAuthorize

佐手、 提交于 2019-12-01 22:50:00

问题


I want to redirect some pages to the login page instead of page 403.

By default BjyAuthorize redirects everything to a 403 page. Is it possible to configure this behavior?

I found this: RedirectionStrategy. How do I use this?


回答1:


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




回答2:


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



回答3:


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

This way, you can extend the UnauthorizedStrategy.



来源:https://stackoverflow.com/questions/17457134/how-to-redirect-to-the-login-page-with-bjyauthorize

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