def fulfil_client(self):
     key = 'fulfil:user:%s:context' % self.token
     context = redis_store.get(key)
     if context:
         client = Client(self.subdomain,
                         auth=BearerAuth(self.token),
                         context=json.loads(context))
     else:
         client = Client(self.subdomain, auth=BearerAuth(self.token))
         redis_store.set(key, json.dumps(client.context), 300)  # TTL 5min
     return client
示例#2
0
def get_fulfil():
    subdomain = Config.FULFIL_SUBDOMAIN
    offline_access_token = Config.FULFIL_OFFLINE_ACCESS_TOKEN
    try:
        return Client(
            subdomain,
            auth=BearerAuth(offline_access_token)
        )
    except ClientError, e:
        if e.code == 401:
            # unauthorized
            flask.abort(flask.redirect(flask.url_for('user.logout')))
        raise
示例#3
0
 def init_app(self, app):
     '''Initalizes the application with the extension.
     :param app: The Flask application object.
     '''
     offline_access_token = app.config.get('FULFIL_OFFLINE_ACCESS_TOKEN')
     if offline_access_token:
         self.client = Client(app.config['FULFIL_SUBDOMAIN'],
                              auth=BearerAuth(offline_access_token))
     else:
         self.client = Client(
             app.config['FULFIL_SUBDOMAIN'],
             app.config['FULFIL_API_KEY'],
         )
     app.jinja_env.filters['client_url'] = client_url
示例#4
0
def get_fulfil():
    if 'fulfil' not in flask.session:
        return

    session_data = flask.session['fulfil']
    try:
        return Client(
            flask.session['subdomain'],
            auth=BearerAuth(
                session_data['oauth_token']['access_token']
            )
        )
    except ClientError as e:
        if e.code == 401:
            # unauthorized
            # TODO: Use refresh token if possible
            flask.abort(flask.redirect(flask.url_for('user.logout')))
        raise
示例#5
0
def get_fulfil():
    subdomain = Config.FULFIL_SUBDOMAIN

    access_token = Config.FULFIL_OFFLINE_ACCESS_TOKEN

    if 'FULFIL_ACCESS_TOKEN' in flask.session:
        # Use current login token
        access_token = flask.session['FULFIL_ACCESS_TOKEN']

    if access_token is None:
        flask.abort(403)

    try:
        return Client(
            subdomain,
            auth=BearerAuth(access_token)
        )
    except ClientError, e:
        if e.code == 401:
            # unauthorized
            flask.abort(flask.redirect(flask.url_for('user.logout')))
        raise
示例#6
0
def oauth_client():
    return Client('demo', auth=BearerAuth(os.environ['FULFIL_OAUTH_TOKEN']))