Exemple #1
0
def shopify_callback():
    if not 'shop_name' in session:
        abort(401)

    shop_name = session['shop_name']

    # Get the base app credentials
    base_credentials = app.config.get('SHOPIFY_CREDENTIALS')

    #Generate a new credential object with the base values
    credentials = Credentials(
        api_key=base_credentials.api_key,
        secret=base_credentials.secret
    )

    #Setup a shopify adapter instance to create the authorization url
    shopify = Shopify(shop_name=shop_name, credentials=credentials)

    #Verify the signature
    if not shopify.verify_signature(request.args):
        raise Exception("invalid signature")

    #Update the credentials object with the provided temporary code
    credentials.code = request.args.get('code')

    #Exchange the code for an access token
    shopify.setup_access_token()

    #Store the access token in the session
    session['access_token'] = credentials.oauth_access_token

    return redirect(url_for('shop.view'))