AuthKit 0.4.0
I’m pleased to announce the release of AuthKit 0.4.0. It has taken me a lot longer than it should have but it is out. You can download AuthKit here. Please note that the config file format has changed a bit since 0.3 so have a look at the Pylons Book chapters to read about the new version.
Please let me know about any bugs and I’ll release a 0.4.1 if necessary.
IE7 produces different HTTP Digest headers
Rohan Barnett has been pointing out a bug in AuthKit he has experienced for quite a while. For some reason AuthKit’s digest implementation worked in every browser apart from IE7. All that happens is that IE keeps showing you the pop to enter your username and password.
Today I finally tracked down the problem. IE7’s headers look like this:
Digest username="asd",realm="Test Realm",nonce="b99bd0d4c8c5f9d0448910ea6ab5be28",uri="/private",cnonce="9e1a7dc289b9ce26090ae88cb5433cff",nc=00000005,response="1709e5d0616f43a63c3c77b0866ef3d3",qop="auth",opaque="b41c8bf75355adb523d1b05f8f2707d8"
Every other browser’s look like something like this with spaces after the commas:
Digest username="asd", realm="Test Realm", nonce="7f05810618404280262353bb51bd998c", uri="/private", response="e8e97e5d335af696ab3dd169da02b7b8", opaque="d0837206408ac92195012fb0ce233e91", qop=auth, nc=00000002, cnonce="9d6a68265679ac27"
The AuthKit code was splitting on ", " not on ",". I’ve corrected this, fixing ticket #31 and it now works but I thought I’d blog about it here in case anyone else experiences the same issue.
Pylons: Mako Templates in AuthKit
AuthKit’s form and openid methods take a authkit.form.template.obj or authkit.openid.template.obj argument which is a Paste import string to a function which returns a template. This is very handy if you want AuthKit to render a sign in page which looks the same as the rest of your site because you can use your existing templates. Here’s how…
If your project was named myproject you could create a file in myproject/lib/auth.py which looks like this:
import pylons
from pylons.templating import Buffet
from pylons import config
import myproject.lib.helpers as h
class MyBuffet(Buffet):
def _update_names(self, ns):
return ns
def_eng = config['buffet.template_engines'][0]
buffet = MyBuffet(
def_eng['engine'],
template_root=def_eng['template_root'],
**def_eng['template_options']
)
for e in config['buffet.template_engines'][1:]:
buffet.prepare(
e['engine'],
template_root=e['template_root'],
alias=e['alias'],
**e['template_options']
)
class State:
pass
c = State()
c.user = 'None'
def make_template():
return buffet.render(
template_name="/core/derived/signin.mako",
namespace=dict(h=h, c=State())
).replace("%", "%%").replace("FORM_ACTION", "%s")
There is quite a lot of boiler plate because you need to setup your own instance of buffet just for this rendering but it does all work. You can then set the AuthKit config option like this:
authkit.form.template.obj = myproject.lib.auth:make_template
Logging In Pylons
Pylons 0.9.6rc1 introduces a new logging mechanism which isn’t too well documented at the moment. This is the old method I used before 0.9.6rc1 came out.
In config/middleware.py Add this code at the end:
import logging, sys
def setup_logging(key, level=logging.DEBUG,
formatter=”%(asctime)s %(levelname)s %(module)s %(messages)s”
):
log = logging.getLogger(key)
console = logging.StreamHandler(sys.stderr)
log.setLevel(level)
log.addHandler(console)
Then for each log you want recorded you just add this at the bottom of the file:
setup_logging('authkit.authenticate', logging.DEBUG)
This is particularly useful for tracking down problems with AuthKit. You might want to add all these for example
setup_logging('authkit.authenticate', logging.DEBUG)
setup_logging(’authkit.authenticate.form’, logging.DEBUG)
setup_logging(’authkit.authenticate.cookie’, logging.DEBUG)