2

I have a custom decorator that I implemented to use Duo Push 2FA. Which looks something like this:

views.py

@duo_auth.duo_auth_required
def get_stuff(request):
    page = request.GET.get('page', 1)

If it does not meet the requirements it'll bounce you to a page that requires you to authenticate via DUO. And I've gone as far as to decorate all my views with it, but when it comes down to the admin page, I'm not entirely sure how to integrate it there.

urlpatterns = [
    url(r'^admin/', admin.site.urls),

Is it possible to add the decorator on the urls pattern?

Stupid.Fat.Cat
  • 10,755
  • 23
  • 83
  • 144
  • Is adding the decorator to the admin class not working? Decorating `class FooModelAdmin(ModelAdmin): pass` for example. This also seems like a better case for a middleware since you're applying it everywhere. – kylieCatt Nov 21 '16 at 23:53
  • @IanAuld I'm not familiar with adding the decorator to a class. How would you go about doing that? Import the model in models.py and just add the decorator to the class? – Stupid.Fat.Cat Nov 21 '16 at 23:54
  • @IanAuld I think so as well. I'm considering moving this to the middleware layer. – Stupid.Fat.Cat Nov 21 '16 at 23:55
  • In [this snippet](https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin) for example just decorating the `AuthorAdmin` class the same way you have for your function. – kylieCatt Nov 21 '16 at 23:58
  • @IanAuld seems like this isn't working for me. I suppose this might be a good time to switch over to the middleware layer then – Stupid.Fat.Cat Nov 22 '16 at 00:05
  • Another approach is to [enable `login_required` and `duo_auth_required` "everywhere" (except login/logout)](https://stackoverflow.com/questions/2164069/best-way-to-make-djangos-login-required-the-default). This will apply to every view including the admin site. (You may ask, what about the landing page, etc? Those can be handled on a project by project basis, personally I try not to serve those from the same Django app as the one that requires 2FA - segmentation). – floer32 Dec 01 '17 at 21:34

0 Answers0