def openid_association(cls, assoc): secret = assoc.secret if not isinstance(secret, six.binary_type): secret = secret.encode() return OpenIdAssociation(assoc.handle, base64.decodestring(secret), assoc.issued, assoc.lifetime, assoc.assoc_type)
def oids(cls, server_url, handle=None): kwargs = {'server_url': server_url} if handle is not None: kwargs['handle'] = handle return sorted([ (assoc.id, OpenIdAssociation(assoc.handle, base64.decodestring(assoc.secret), assoc.issued, assoc.lifetime, assoc.assoc_type)) for assoc in cls.get(**kwargs) ], key=lambda x: x[1].issued, reverse=True)
def getAssociation(self, server_url, handle=None): logging.debug('store: get %s', server_url) try: assoc = Association.objects.filter( issued__gt = (int(time.time()) - F('lifetime')), server_url = server_url ) if handle is not None: assoc = assoc.filter(handle = handle) assoc = assoc.order_by('-issued')[0] return OpenIdAssociation( handle = assoc.handle, secret = base64.urlsafe_b64decode(assoc.secret), issued = assoc.issued, lifetime = assoc.lifetime, assoc_type = assoc.assoc_type, ) except: return None