3

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?

anasaitali
  • 1,504
  • 21
  • 30

3 Answers3

12

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

anasaitali
  • 1,504
  • 21
  • 30
  • 1
    Ah, looks like the author integrated this strategy into the new version. – Ruben Jul 04 '13 at 00:17
  • And how exactly you set to what route you want to redirect? – Sharikov Vladislav May 15 '14 at 21:17
  • 1
    @Sharikov, the instructions on how to set the route are here: https://github.com/bjyoungblood/BjyAuthorize/blob/master/docs/unauthorized-strategies.md – Onshop Jul 10 '14 at 10:23
  • Is there way to setup RedirectUri in bjyauthorize.global.php? This is how I set Redirection Strategy there: 'unauthorized_strategy' => 'BjyAuthorize\View\RedirectionStrategy'. – vlr Nov 06 '14 at 21:26
3

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',
        ),
Ruben
  • 5,043
  • 2
  • 25
  • 49
  • I've put this code in `config/autoload/bjyauthorize.global.php` with the class by Rob allen in the right place. But it does not seem to work. – anasaitali Jul 03 '13 at 23:53
  • That's right, you have to add the service_manager config part to be able to instantiate it. See edit above in the answer. – Ruben Jul 04 '13 at 00:16
  • I put both configuration values inside bjyauthorize.config.php and it did the trick. To me, it seems it's more relevant that way :) – vortex Aug 05 '13 at 11:36
  • I made this work by also adding the class to the getServiceConfig function in Module.php as a factory. – Akin Williams Aug 21 '15 at 15:21
0

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

This way, you can extend the UnauthorizedStrategy.

juworld
  • 140
  • 1
  • 15