def verify(self, *args, **kw): provider = request.params.get('provider') service = get_provider(provider) auth = service.responder() try: user = auth.verify() account = user['profile']['accounts'][0] if not user.get('oauth_token') and not user.get('oauth_token_secret'): raise Exception('Unable to get OAUTH access') acct = self._get_or_create_account(provider, account['userid'], account['username']) acct.profile = user['profile'] acct.oauth_token = user.get('oauth_token', None) if 'oauth_token_secret' in user: acct.oauth_token_secret = user['oauth_token_secret'] acct.updated = UTCDateTime.now() try: Session.commit() except UnicodeEncodeError, e: log.exception("***** UnicodeEncodeError! %r: %r: %r %r" % (acct.domain, acct.userid, acct.username,acct.json_attributes,)) raise e # XXX argh, this is also done in get_or_create above, but we have to # ensure we have the updated data session[acct.key] = acct.to_dict() session.save()
def verify(self, *args, **kw): provider = request.params.get('provider') log.info("verify request for %r", provider) service = get_provider(provider) auth = service.responder() try: user = auth.verify() account = user['profile']['accounts'][0] if not user.get('oauth_token') and not user.get( 'oauth_token_secret'): raise Exception('Unable to get OAUTH access') acct = self._get_or_create_account(provider, str(account['userid']), account['username']) acct['profile'] = user['profile'] acct['oauth_token'] = user.get('oauth_token', None) if 'oauth_token_secret' in user: acct['oauth_token_secret'] = user['oauth_token_secret'] acct['updated'] = datetime.now().isoformat() session[acct['key']] = acct session.save() except AccessException, e: self._redirectException(e)
def get(self, domain): username = request.params.get('username') userid = request.params.get('userid') group = request.params.get('group', None) startIndex = int(request.params.get('startindex','0')) maxResults = int(request.params.get('maxresults','25')) keys = session.get('account_keys', '').split(',') if not keys: error = {'provider': domain, 'message': "no user session exists, auth required", 'status': 401 } return {'result': None, 'error': error} provider = get_provider(domain) # even if we have a session key, we must have an account for that # user for the specified domain. acct = None for k in keys: a = session.get(k) if a and a.get('domain') == domain and (not username or a.get('username')==username and not userid or a.get('userid')==userid): acct = a break if not acct: error = {'provider': domain, 'message': "not logged in or no user account for that domain", 'status': 401 } return {'result': None, 'error': error} result, error = provider.api(acct).getcontacts(startIndex, maxResults, group) return {'result': result, 'error': error}
def get(self, domain): username = request.POST.get('username') userid = request.POST.get('userid') group = request.POST.get('group', None) startIndex = int(request.POST.get('startindex', '0')) maxResults = int(request.POST.get('maxresults', '25')) keys = session.get('account_keys', '').split(',') account_data = request.POST.get('account', None) if not keys: error = { 'provider': domain, 'message': "no user session exists, auth required", 'status': 401 } metrics.track(request, 'contacts-unauthed', domain=domain) return {'result': None, 'error': error} provider = get_provider(domain) # even if we have a session key, we must have an account for that # user for the specified domain. if account_data is not None: acct = json.loads(account_data) else: # support for old accounts in the session store acct = None for k in keys: a = session.get(k) if a and a.get('domain') == domain and ( not username or a.get('username') == username and not userid or a.get('userid') == userid): acct = a break if not acct: metrics.track(request, 'contacts-noaccount', domain=domain) error = { 'provider': domain, 'message': "not logged in or no user account for that domain", 'status': 401 } return {'result': None, 'error': error} try: result, error = provider.api(acct).getcontacts( startIndex, maxResults, group) except OAuthKeysException, e: # more than likely we're missing oauth tokens for some reason. error = { 'provider': domain, 'message': "not logged in or no user account for that domain", 'status': 401 } result = None metrics.track(request, 'contacts-oauth-keys-missing', domain=domain)
def send(self): result = {} error = None # If we don't have a key in our session we bail early with a # 401 domain = request.POST.get("domain") message = request.POST.get("message", "") username = request.POST.get("username") longurl = request.POST.get("link") shorten = asbool(request.POST.get("shorten", 0)) shorturl = request.POST.get("shorturl") userid = request.POST.get("userid") to = request.POST.get("to") if not domain: error = {"message": "'domain' is not optional", "code": constants.INVALID_PARAMS} return {"result": result, "error": error} keys = session.get("account_keys", "").split(",") if not keys: error = {"provider": domain, "message": "no user session exists, auth required", "status": 401} return {"result": result, "error": error} provider = get_provider(domain) # even if we have a session key, we must have an account for that # user for the specified domain. acct = None for k in keys: a = session.get(k) if a and a.get("domain") == domain and (a.get("username") == username or a.get("userid") == userid): acct = a break if not acct: error = {"provider": domain, "message": "not logged in or no user account for that domain", "status": 401} return {"result": result, "error": error} args = copy.copy(request.POST) if shorten and not shorturl and longurl: u = urlparse(longurl) if not u.scheme: longurl = "http://" + longurl shorturl = Link.get_or_create(longurl).short_url args["shorturl"] = shorturl # send the item. try: result, error = provider.api(acct).sendmessage(message, args) except ValueError, e: import traceback traceback.print_exc() # XXX we need to handle this better, but if for some reason the # oauth values are bad we will get a ValueError raised error = {"provider": domain, "message": "not logged in or no user account for that domain", "status": 401} return {"result": result, "error": error}
def get(self, domain): username = request.POST.get('username') userid = request.POST.get('userid') group = request.POST.get('group', None) startIndex = int(request.POST.get('startindex','0')) maxResults = int(request.POST.get('maxresults','25')) keys = session.get('account_keys', '').split(',') account_data = request.POST.get('account', None) if not keys: error = {'provider': domain, 'message': "no user session exists, auth required", 'status': 401 } metrics.track(request, 'contacts-unauthed', domain=domain) return {'result': None, 'error': error} provider = get_provider(domain) # even if we have a session key, we must have an account for that # user for the specified domain. if account_data is not None: acct = json.loads(account_data) else: # support for old accounts in the session store acct = None for k in keys: a = session.get(k) if a and a.get('domain') == domain and (not username or a.get('username')==username and not userid or a.get('userid')==userid): acct = a break if not acct: metrics.track(request, 'contacts-noaccount', domain=domain) error = {'provider': domain, 'message': "not logged in or no user account for that domain", 'status': 401 } return {'result': None, 'error': error} try: result, error = provider.api(acct).getcontacts(startIndex, maxResults, group) except OAuthKeysException, e: # more than likely we're missing oauth tokens for some reason. error = {'provider': domain, 'message': "not logged in or no user account for that domain", 'status': 401 } result = None metrics.track(request, 'contacts-oauth-keys-missing', domain=domain)
def verify(self, *args, **kw): provider = request.params.get("provider") log.info("verify request for %r", provider) service = get_provider(provider) auth = service.responder() try: user = auth.verify() account = user["profile"]["accounts"][0] if not user.get("oauth_token") and not user.get("oauth_token_secret"): raise Exception("Unable to get OAUTH access") acct = self._get_or_create_account(provider, str(account["userid"]), account["username"]) acct["profile"] = user["profile"] acct["oauth_token"] = user.get("oauth_token", None) if "oauth_token_secret" in user: acct["oauth_token_secret"] = user["oauth_token_secret"] acct["updated"] = datetime.now().isoformat() session[acct["key"]] = acct session.save() except AccessException, e: self._redirectException(e)
def verify(self, *args, **kw): provider = request.params.get('provider') log.info("verify request for %r", provider) service = get_provider(provider) auth = service.responder() try: user = auth.verify() account = user['profile']['accounts'][0] if not user.get('oauth_token') and not user.get('oauth_token_secret'): raise Exception('Unable to get OAUTH access') acct = self._get_or_create_account(provider, str(account['userid']), account['username']) acct['profile'] = user['profile'] acct['oauth_token'] = user.get('oauth_token', None) if 'oauth_token_secret' in user: acct['oauth_token_secret'] = user['oauth_token_secret'] acct['updated'] = datetime.now().isoformat() session[acct['key']] = acct session.save() except AccessException, e: self._redirectException(e)
def verify(self, *args, **kw): provider = session.pop('oauth_provider') session.save() service = get_provider(provider) auth = service.responder() try: user = auth.verify() account = user['profile']['accounts'][0] acct = self._get_or_create_account(provider, account['userid'], account['username']) acct.profile = user['profile'] acct.oauth_token = user.get('oauth_token', None) if 'oauth_token_secret' in user: acct.oauth_token_secret = user['oauth_token_secret'] acct.updated = UTCDateTime.now() Session.commit() # XXX argh, this is also done in get_or_create above, but we have to # ensure we have the updated data session[acct.key] = acct.to_dict() session.save() except AccessException, e: self._redirectException(e)
def authorize(self, *args, **kw): provider = request.POST['domain'] log.info("authorize request for %r", provider) service = get_provider(provider) return service.responder().request_access()
def send(self): result = {} error = None # If we don't have a key in our session we bail early with a # 401 domain = request.POST.get('domain') message = request.POST.get('message', '') username = request.POST.get('username') longurl = request.POST.get('link') shorten = asbool(request.POST.get('shorten', 0)) shorturl = request.POST.get('shorturl') userid = request.POST.get('userid') to = request.POST.get('to') account_data = request.POST.get('account', None) if not domain: error = { 'message': "'domain' is not optional", 'code': constants.INVALID_PARAMS } return {'result': result, 'error': error} keys = session.get('account_keys', '').split(',') if not keys: error = { 'provider': domain, 'message': "no user session exists, auth required", 'status': 401 } metrics.track(request, 'send-unauthed', domain=domain) return {'result': result, 'error': error} provider = get_provider(domain) # even if we have a session key, we must have an account for that # user for the specified domain. if account_data is not None: acct = json.loads(account_data) else: # support for old account data in session store acct = None for k in keys: a = session.get(k) if a and a.get('domain') == domain and ( a.get('username') == username or a.get('userid') == userid): acct = a break if not acct: metrics.track(request, 'send-noaccount', domain=domain) error = { 'provider': domain, 'message': "not logged in or no user account for that domain", 'status': 401 } return {'result': result, 'error': error} args = copy.copy(request.POST) if shorten and not shorturl and longurl: link_timer = metrics.start_timer(request, long_url=longurl) u = urlparse(longurl) if not u.scheme: longurl = 'http://' + longurl shorturl = shorten_link(longurl) link_timer.track('link-shorten', short_url=shorturl) args['shorturl'] = shorturl acct_hash = hashlib.sha1("%s#%s" % ((username or '').encode('utf-8'), (userid or '').encode('utf-8'))).hexdigest() timer = metrics.start_timer(request, domain=domain, message_len=len(message), long_url=longurl, short_url=shorturl, acct_id=acct_hash) # send the item. try: result, error = provider.api(acct).sendmessage(message, args) except OAuthKeysException, e: # XXX - I doubt we really want a full exception logged here? #log.exception('error providing item to %s: %s', domain, e) # XXX we need to handle this better, but if for some reason the # oauth values are bad we will get a ValueError raised error = { 'provider': domain, 'message': "not logged in or no user account for that domain", 'status': 401 } metrics.track(request, 'send-oauth-keys-missing', domain=domain) timer.track('send-error', error=error) return {'result': result, 'error': error}