def _Dynamic_Authenticate(self, req, resp): """Authenticate Cyclozzo User""" username, passwd_hash = req.get_auth_vars() args = {'user_id': username, 'password_hash': passwd_hash, 'app_id': get_yaml().application} logging.debug('authenticating with console at http://%s:%d' %(self.console_address, self.console_port)) try: res = urlfetch.fetch('http://%s:%d/api/authenticate?%s' %(self.console_address, self.console_port, urllib.urlencode(args))).content authenticated, admin, email, msg = simplejson.loads(res) except Exception, ex: logging.error('Error authenticating user %s' %username) authenticated, email, admin, msg = False, '', False, 'Error authenticating user: %s' %str(ex)
def get_authenticated_user(self, callback, openid_endpoint=None): """Fetches the authenticated user data upon redirect. This method should be called by the handler that receives the redirect from the authenticate_redirect() or authorize_redirect() methods. :param callback: A function that is called after the authentication attempt. It is called passing a dictionary with the requested user attributes or None if the authentication failed. :param openid_endpoint: OpenId provider endpoint. For example, 'https://www.google.com/accounts/o8/ud'. :returns: The result from the callback function. """ # Changed method to POST. See: # https://github.com/facebook/tornado/commit/e5bd0c066afee37609156d1ac465057a726afcd4 # Verify the OpenID response via direct request to the OP url = openid_endpoint or self._OPENID_ENDPOINT logging.debug('Request Params: %s' % str(dir(self.request))) args_lists = {} for entry in self.request.query.split('&'): k, v = entry.split('=') if k in args_lists: args_lists[k].append(v) else: args_lists[k] = [v] logging.debug('--> %r' % args_lists.items()) #args = dict((k, v[-1].encode('utf8')) for k, v in self.request.args.lists()) args = dict((k, v[-1].encode('utf8')) for k, v in args_lists.items()) args['openid.mode'] = u'check_authentication' try: response = urlfetch.fetch(url, deadline=10, method=urlfetch.POST, payload=urllib.urlencode(args)) if response.status_code < 200 or response.status_code >= 300: logging.warning('Invalid OpenID response: %s', response.content) else: return self._on_authentication_verified(callback, response) except urlfetch.DownloadError, e: logging.exception(e)
def get_authenticated_user(self, callback, openid_endpoint=None): """Fetches the authenticated user data upon redirect. This method should be called by the handler that receives the redirect from the authenticate_redirect() or authorize_redirect() methods. :param callback: A function that is called after the authentication attempt. It is called passing a dictionary with the requested user attributes or None if the authentication failed. :param openid_endpoint: OpenId provider endpoint. For example, 'https://www.google.com/accounts/o8/ud'. :returns: The result from the callback function. """ # Changed method to POST. See: # https://github.com/facebook/tornado/commit/e5bd0c066afee37609156d1ac465057a726afcd4 # Verify the OpenID response via direct request to the OP url = openid_endpoint or self._OPENID_ENDPOINT logging.debug('Request Params: %s' %str(dir(self.request))) args_lists = {} for entry in self.request.query.split('&'): k, v = entry.split('=') if k in args_lists: args_lists[k].append(v) else: args_lists[k] = [v] logging.debug('--> %r' %args_lists.items()) #args = dict((k, v[-1].encode('utf8')) for k, v in self.request.args.lists()) args = dict((k, v[-1].encode('utf8')) for k, v in args_lists.items()) args['openid.mode'] = u'check_authentication' try: response = urlfetch.fetch(url, deadline=10, method=urlfetch.POST, payload=urllib.urlencode(args)) if response.status_code < 200 or response.status_code >= 300: logging.warning('Invalid OpenID response: %s', response.content) else: return self._on_authentication_verified(callback, response) except urlfetch.DownloadError, e: logging.exception(e)
def _Dynamic_Authenticate(self, req, resp): """Authenticate Cyclozzo User""" username, passwd_hash = req.get_auth_vars() args = { 'user_id': username, 'password_hash': passwd_hash, 'app_id': get_yaml().application } logging.debug('authenticating with console at http://%s:%d' % (self.console_address, self.console_port)) try: res = urlfetch.fetch('http://%s:%d/api/authenticate?%s' % (self.console_address, self.console_port, urllib.urlencode(args))).content authenticated, admin, email, msg = simplejson.loads(res) except Exception, ex: logging.error('Error authenticating user %s' % username) authenticated, email, admin, msg = False, '', False, 'Error authenticating user: %s' % str( ex)