3

Say I have a simple structure:

app = webapp2.WSGIApplication([
    (r'/', 'pages.login'),
    (r'/profile', 'pages.profile'),
    (r'/dashboard', 'pages.dash'),
], debug=True)

Basically all pages require authentication except for the login. If visitor tries to reach a restrictive page and he isn't authorized (or lacks privileges) then he gets redirected to the login view.

The question is about the routing design. Should I check the auth and ACL privs in each of the modules (pages.profile and pages.dash from example above), or just pass all requests through the single routing mechanism:

app = webapp2.WSGIApplication([
    (r'/', 'pages.login'),
    (r'/.+', 'router')
], debug=True)

I'm still quite new to the GAE, but my app requires authentication as well as ACL. I'm aware that there's login directive on the server config level, but I don't know how it works and how I can tight it with my ACL logic and what's worse I cannot estimate time needed to get it running. Besides, it looks only to provide only 2 user groups: admin and user.

In any case, that's the configuration I use:

handlers:
- url: /favicon.ico
  static_files: static/favicon.ico
  upload: static/favicon.ico
- url: /static/*
  static_dir: static
- url: .*
  script: main.app
  secure: always

Or I miss something here and ACL can be set in the config file? Thanks.

1 Answer 1

2

The login/admin settings in app.yaml are only useful if you're using Google accounts for login. If you're not using Google accounts, you'll have to implement things yourself.

I've done it by having my handlers subclass from a base handler class I've defined. The base handler implements authentication, redirecting, logging, and some other common functionality. By default, the base handler requires that the user be logged in; then I override this in the few subclasses that don't require login (safer than the reverse). My admin-only handlers have their own subclass of the base handler, which handles the admin credential verification and redirection.

1
  • Marking this as accepted, since this is exactly the way I ended up going! Thanks for the input, much appreciated. Jul 15, 2013 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.