1 #!/usr/bin/env python 2 3 """ 4 Authentication/authorisation helper classes and functions. 5 """ 6 7 import base64 8 9 class UserInfo: 10 11 """ 12 A class used to represent user information in terms of the authentication 13 scheme employed and the user details. 14 """ 15 16 def __init__(self, auth_header): 17 18 """ 19 Initialise the object with the value of the 'auth_header' - that is, the 20 HTTP Authorization header. 21 """ 22 23 self.scheme, auth_details = auth_header.split(" ") 24 if self.scheme == "Basic": 25 26 # NOTE: Assume that no username or password contains ":". 27 28 self.username, self.password = base64.decodestring(auth_details).split(":") 29 30 else: 31 32 # NOTE: Other schemes not yet supported. 33 34 self.username, self.password = None, None 35 36 # vim: tabstop=4 expandtab shiftwidth=4