1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/WebStack/Helpers/Auth.py Sun Feb 08 21:42:02 2004 +0000
1.3 @@ -0,0 +1,36 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Authentication/authorisation helper classes and functions.
1.8 +"""
1.9 +
1.10 +import base64
1.11 +
1.12 +class UserInfo:
1.13 +
1.14 + """
1.15 + A class used to represent user information in terms of the authentication
1.16 + scheme employed and the user details.
1.17 + """
1.18 +
1.19 + def __init__(self, auth_header):
1.20 +
1.21 + """
1.22 + Initialise the object with the value of the 'auth_header' - that is, the
1.23 + HTTP Authorization header.
1.24 + """
1.25 +
1.26 + self.scheme, auth_details = auth_header.split(" ")
1.27 + if self.scheme == "Basic":
1.28 +
1.29 + # NOTE: Assume that no username or password contains ":".
1.30 +
1.31 + self.username, self.password = base64.decodestring(auth_details).split(":")
1.32 +
1.33 + else:
1.34 +
1.35 + # NOTE: Other schemes not yet supported.
1.36 +
1.37 + self.username, self.password = None, None
1.38 +
1.39 +# vim: tabstop=4 expandtab shiftwidth=4