Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.assertRaises(Exception, lambda: bigcommerce.api.BigcommerceApi(client_id='123', basic_auth=('admin', 'token')))
def auth_callback():
# Put together params for token request
code = flask.request.args['code']
context = flask.request.args['context']
scope = flask.request.args['scope']
store_hash = context.split('/')[1]
redirect = app.config['APP_URL'] + flask.url_for('auth_callback')
# Fetch a permanent oauth token. This will throw an exception on error,
# which will get caught by our error handler above.
client = BigcommerceApi(client_id=client_id(), store_hash=store_hash)
token = client.oauth_fetch_token(client_secret(), code, context, scope, redirect)
bc_user_id = token['user']['id']
email = token['user']['email']
access_token = token['access_token']
# Create or update store
store = Store.query.filter_by(store_hash=store_hash).first()
if store is None:
store = Store(store_hash, access_token, scope)
db.session.add(store)
db.session.commit()
else:
store.access_token = access_token
store.scope = scope
db.session.add(store)
db.session.commit()
def index():
# Lookup user
storeuser = StoreUser.query.filter_by(id=flask.session['storeuserid']).first()
if storeuser is None:
return "Not logged in!", 401
store = storeuser.store
user = storeuser.user
# Construct api client
client = BigcommerceApi(client_id=client_id(),
store_hash=store.store_hash,
access_token=store.access_token)
# Fetch a few products
products = client.Products.all(limit=10)
# Render page
context = dict()
context['products'] = products
context['user'] = user
context['store'] = store
context['client_id'] = client_id()
context['api_url'] = client.connection.host
return render('index.html', context)
def load():
# Decode and verify payload
payload = flask.request.args['signed_payload']
user_data = BigcommerceApi.oauth_verify_payload(payload, client_secret())
if user_data is False:
return "Payload verification failed!", 401
bc_user_id = user_data['user']['id']
email = user_data['user']['email']
store_hash = user_data['store_hash']
# Lookup store
store = Store.query.filter_by(store_hash=store_hash).first()
if store is None:
return "Store not found!", 401
# Lookup user and create if doesn't exist (this can happen if you enable multi-user
# when registering your app)
user = User.query.filter_by(bc_id=bc_user_id).first()
if user is None: