Angular route async authorization

后端 未结 4 1694
一整个雨季
一整个雨季 2020-12-11 17:46

Angular doesn\'t provide any authorization/access permission on routing (I\'m talking default Angular route 1.x and not beta 2.0 or UI route). But I do have to implement it.

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 18:30

    I've approached this issue many times, I've also developed a module (github). My module (built on top of ui.router) is based on $stateChangeStart (ui.router event) but the concept is the same with the default ng.route module, it's just a different implementation way.

    In conclusion I think that handling routing changing events is not the good way to perform an authentication checking: For example, when we need to obtain the acl via ajax the events can't help us.

    A good way, I think, could be to automatically append a resolve to each "protected" state...

    Unfortunately ui.Router doesn't provides an API to intercept the state creation so I started my module rework with a little workaround on top of $stateProvider.state method.

    Definitively, I'm looking for different opinions in order to find the correct way to implement a Authentication Service in AngularJS.

    if are there anyone that is interested in this research... please, open an issue on my github and the discuss

提交回复
热议问题