Giter Club home page Giter Club logo

flask-shopify's Introduction

Installation

pip install flask-shopify

Settings/Config

The API Key and shared secret should be set on the config of the app

SHOPIFY_SHARED_SECRET   = Your app's shared secret key with Shopify.
SHOPIFY_API_KEY         = Your app's API key.

Example usage

Setup the app

from flask_shopify import Shopify

app = Flask(__name__)
shopify = Shopify(app)

or, if you are using the factory pattern

from flask_shopify import Shopify

shopify = Shopify()

# ...
# when app is available

shoify.init_app(app)

Using shopify_login_required decorator

The decorator allows protecting handles with a shopify session.

Before you can use the decorator, ensure that a login view is configured. This is where fulfil will redirect the user is there is no login session yet.

# Set the login view if you plan on using shopify_login_required
# decorator
shopify.login_view = 'auth.login'

Using decorator

from flask_shopify import shopify_login_required

@shopify_login_required
@app.route('/product')
def product():
    product = shopify.Product.find(
        request.args['id']
    )

When using admin links

If you are using admin links, then shopify launches the url with the shop in the parameters. You can use the assert_shop decorator to ensure that the current shop the user is logged into is also the shop where the user clicked the admin link.

from flask_shopify import shopify_login_required, assert_shop

@shopify_login_required
@assert_shop
@app.route('/product')
def product():
    product = shopify.Product.find(
        request.args['id']
    )

Login, logout and oauth authentication

Built-in helpers achieve all of this.

Login

@app.route('/login')
def login():
    shop = request.args.get('shop')
    if shop:
        return shopify.install(
            shop,
            ['write_products'],
            url_for('.authenticate', _external=True)
        )
    return render_template('select-shop.html')

Authenticate after Oauth dance

@app.route('/authenticate')
def authenticate():
    shopify_session = shopify.authenticate()
    if shopify_session:
        return redirect(
            session.pop('next_url', url_for('.index'))
        )
    return "Login Failed"

Logout

@app.route('/logout')
def logout():
    shopify.logout()
    return redirect('home')

flask-shopify's People

Contributors

anmol-gulati avatar sharoonthomas avatar tarunbhardwaj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.