def get(self, action): if action == 'request': expired = datetime.datetime.now() - datetime.timedelta(minutes=10) expired_tokens = OAuthRequestToken.all().filter('created <', expired).fetch(20) for token in expired_tokens: token.delete() elif action == 'access': expired = datetime.datetime.now() - datetime.timedelta(hours=6) expired_tokens = OAuthAccessToken.all().filter('modified <', expired).fetch(20) q = taskqueue.Queue('background') for i, token in enumerate(expired_tokens): key_name = token.key().name() t = taskqueue.Task(url='/task/access', params=dict(key_name=key_name), countdown=i*2) q.add(t) elif action == 'graph': q = taskqueue.Queue('fastest') t = taskqueue.Task(url='/task/graph') q.add(t) elif action == 'image': expired = datetime.datetime.now() - datetime.timedelta(days=7) expired_tokens = UserStatus.all().filter('profile_image_updated <', expired).fetch(10) q = taskqueue.Queue('background') for i, token in enumerate(expired_tokens): key_name = token.key().name() t = taskqueue.Task(url='/task/image', params=dict(key_name=key_name), countdown=i*2) q.add(t)
def get(self): fitbit_oauth = util.create_fitbit_oauth_service() request_token, request_token_secret = fitbit_oauth.get_request_token(header_auth=True) #store token and secret in DB userid = util.load_session_credentials(self)[0] token_info = OAuthRequestToken(key_name=userid) token_info.request_token=request_token token_info.request_token_secret=request_token_secret token_info.put() authorize_url = fitbit_oauth.get_authorize_url(request_token) # Perform the redirect. self.redirect(str(authorize_url))
def _remove_fitbit_device(self): """Delete Fitbit device.""" try: api = FitbitAPI(self.userid) if api.is_ready(): api.delete_subscription(self.userid) except: logging.warn('Cannot delete subscription for user %s', userid) token_entity = OAuthRequestToken.get_by_key_name(self.userid) if token_entity: token_entity.delete()
def get(self): logging.debug('Cron job for Glass updates triggered') updates = FitbitStats.gql('WHERE reported = FALSE and steps > 0') for u in updates: userid = u.key().name() logging.debug('Found update for user %s', userid) if util.get_preferences(userid).hourly_updates: _insert_stats_to_glass(userid, u, util.get_fitbit_goals(userid), True) users = OAuthRequestToken.all() for u in users: userid = u.key().name() if util.get_preferences(userid).battery_level: _check_battery_level(userid)
def callback(self): oauth_token = self.handler.request.get('oauth_token') if not oauth_token: self.login() chk = libs.cpu.CPUChecker("auth.callback") # Request Token chk.kokokara() request_token = OAuthRequestToken.get_request_token(oauth_token) chk.kokomade("OAuthRequestToken.get_request_token") if not request_token: logging.warning('callback: None Request Token') return chk.kokokara() access_url = self.client. \ get_data_from_signed_url(self.client.access_token_url, request_token) request_token.delete() chk.kokomade("request_token.delete") # Access Token try: params = dict(token.split('=') for token in access_url.split('&')) except: logging.warning('callback: Invalid URL=%s' % access_url) return name = params.get('screen_name') if not name: logging.warning('callback: screen_name is None') return chk.kokokara() access_token = OAuthAccessToken.get_access_token(params) access_token._name = name chk.kokomade("OAuthAccessToken.get_access_token") return access_token
def get_request_url(self): request_url = self.get_data_from_signed_url(self.request_token_url) request_token = OAuthRequestToken.set_request_token(request_url) oauth_callback = { 'oauth_callback': self.oauth_callback } return self.get_signed_url( \ self.user_auth_url, request_token, **oauth_callback)
def get_oauth_token_for_user(userid): return OAuthRequestToken.get(db.Key.from_path('OAuthRequestToken', userid))