def get_preauth_token(self, account_name, expires=0): if not self.preauth_key: raise self.NoPreauthKeyProvided ts = int(time.time())*1000 preauth_str = utils.build_preauth_str(self.preauth_key, account_name, ts, expires, admin=self.isadmin) args = urllib.urlencode({ 'account' : account_name, 'by' : 'name', 'timestamp' : ts, 'expires' : expires*1000, 'admin' : "1" if self.isadmin else "0", 'preauth' : preauth_str }) cj = cookielib.CookieJar() browser = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) try: browser.open(self.preauth_url+args) for cookie in cj: if cookie.name == self.TOKEN_COOKIE: return cookie.value except urllib2.HTTPError, e: raise self.RESTBackendError(e)
def mk_auth_token(self, account, admin=False, duration=0): """ Builds an authentification token, using preauth mechanism. See http://wiki.zimbra.com/wiki/Preauth @param duration, in seconds defaults to 0, which means "use account default" @param account : an account object to be used as a selector @returns the auth string """ domain = account.get_domain() try: preauth_key = self.get_domain(domain)['zimbraPreAuthKey'] except KeyError: raise DomainHasNoPreAuthKey(domain) timestamp = int(time.time())*1000 expires = duration*1000 return utils.build_preauth_str(preauth_key, account.name, timestamp, expires, admin)
def mk_auth_token(self, account, admin=False, duration=0): """ Builds an authentification token, using preauth mechanism. See http://wiki.zimbra.com/wiki/Preauth :param duration: in seconds defaults to 0, which means "use account default" :param account: an account object to be used as a selector :returns: the auth string """ domain = account.get_domain() try: preauth_key = self.get_domain(domain)['zimbraPreAuthKey'] except KeyError: raise DomainHasNoPreAuthKey(domain) timestamp = int(time.time())*1000 expires = duration*1000 return utils.build_preauth_str(preauth_key, account.name, timestamp, expires, admin)