How to redirect to the login page with BjyAuthoriz

2019-02-24 23:52发布

问题:

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.