Beispiel #1
0
 async def read(self, ids, fields=Available):
     threshold = datetime.datetime.utcnow() - datetime.timedelta(minutes=5)
     query = self.db.query(
         self.__model__).filter_by(**ids).filter(Token.created > threshold)
     entity = query.first()
     if not entity:
         raise ControllerException(404, 'token not found')
     account = self.get_account(entity.provider_id)
     self.policy.grant_read(account, entity, fields)
     if entity.claimed:
         self.current_user.clear()
         self.current_user['user_id'] = entity.account.user_id
         for a in entity.account.user.accounts:
             self.current_user[a.provider_id] = a.id
         entity.account_id = None
         entity.account_provider_id = None
         self.db.commit()
     return entity
Beispiel #2
0
    def _refresh_access(self):
        body = urllib.parse.urlencode({
            'client_id':
            self.settings['key'],
            'client_secret':
            self.settings['secret'],
            'grant_type':
            'refresh_token',
            'refresh_token':
            self.account.refresh_token
        })

        response = yield self.http_client.fetch(self.OAUTH_ACCESS_TOKEN_URL,
                                                method='POST',
                                                body=body,
                                                raise_error=False)
        if response.error:
            message = response.body.decode('utf-8')
            raise ControllerException(403, message)
        access_info = tornado.escape.json_decode(response.body)

        self._update_access_info(access_info)
        self.db.add(self.account)
        self.db.commit()