{ "info": { "author": "Gavin Ballard", "author_email": "gavin@discolabs.com", "bugtrack_url": null, "classifiers": [], "description": "Django Shopify Auth\n===================\n\n[![PyPI version](https://badge.fury.io/py/django-shopify-auth.svg)](http://badge.fury.io/py/django-shopify-auth)\n[![Build Status](https://travis-ci.org/discolabs/django-shopify-auth.svg?branch=master)](https://travis-ci.org/discolabs/django-shopify-auth)\n\nThis Django package makes it easy to integrate Shopify authentication into your Django app. It shares some similarities\nwith the [shopify_django_app](https://github.com/Shopify/shopify_django_app) project, but with a couple of key\ndifferences:\n\n\n* It provides a custom Django Authentication scheme based on `AbstractBaseUser` and `RemoteUserBackend`, meaning shops\n will be authenticated as \"users\" of your Django app. This makes it easier to use common Django patterns and libraries\n (such as accessing the currently authenticated store as `request.user`).\n\n* It persists users' Shopify access tokens in the database, rather than in the Session, meaning your app will be able\n to make API calls on behalf of a user when they're not logged in.\n\n* It supports the authentication flow for new-style \"Embedded SDK\" Shopify apps.\n\n\nThis project provides one package, `shopify_auth`.\nA demonstration Django project using this package is available [here](https://github.com/discolabs/auth_demo).\n\nIf you'd like a detailed breakdown of how to set up an app from scratch using this package, I've recorded a a short\nseries of [five minute screencasts](http://gavinballard.com/shopify-app-in-15-minutes-with-django/) showing how to get\nan app using `django-shopify-auth` up and running in under 15 minutes.\n\nPackage Status\n--------------\nThe package author (@gavinballard) is currently in \"non-active maintenance\" mode.\nI am happy to review and merge pull requests that provide a clear description of\nthe problem they solve and provide a thorough test to avoid any regressions, but\nas I don't use Django in my day-to-day Shopify development any more (the last\nversion I used with much regularity was Django 1.9) I am not actively working on\nthe code.\n\nIf you're using this package on a regular basis and feel you'd be a good fit to\ntake over active development, please [contact me](https://twitter.com/gavinballard).\n\nRequirements\n------------\nTests are run against Django v1.11, v2.0, v2.1 and v2.2. This package may work for\nother Django versions but it's not guaranteed.\n\nAs with the original `shopify_django_app` package, you'll need a [Shopify partner account](http://shopify.com/partners)\nand to have created an app in order to get an API key and secret.\n\n\nPackage Installation and Setup\n------------------------------\nThere are a few moving parts to set up, but hopefully the following instructions will make things straightforward.\n\nWe're assuming in this setup that you're using a standard Django project layout (the sort that's created with the\n`django-admin.py startproject` command). We're also assuming that our project is called `auth_demo` and that the primary\nDjango app inside our project is going to be called `auth_app`.\n\nIf you ever get lost or aren't really sure what to do, you can refer to the [demo app](https://github.com/discolabs/auth_demo).\n\n\n### 1. Install package\nInstallation is super easy via `pip`:\n\n```shell\n> pip install django-shopify-auth\n```\n\nOnce you have the package installed, add `shopify_auth` to your `INSTALLED_APPS`.\n\n\n### 2. Add custom user model\nBecause `shopify_auth` makes use of Django's authentication system, it provides a custom authentication backend\n(`shopify_auth.backends.ShopUserBackend`) which allows authentication through Shopify's OAuth flow.\n\nThis backend requires that the user model for your app (specified by `AUTH_USER_MODEL` in your `settings.py`) inherits\nfrom `shopify_auth.models.AbstractShopUser`. To do this, just add something like this to the `models.py` for your\nDjango app:\n\n```python\n# auth_demo/auth_app/models.py\nfrom shopify_auth.models import AbstractShopUser\n\nclass AuthAppShopUser(AbstractShopUser):\n pass\n```\n\nThen make sure that you have the following line or similar in `settings.py`:\n\n```python\nAUTH_USER_MODEL = 'auth_app.AuthAppShopUser'\n```\n\n\n### 3. Configure settings\nIn addition to setting `AUTH_USER_MODEL`, there are a few more required additions to `settings.py`:\n\n```python\n# Configure Shopify Application settings\nSHOPIFY_APP_NAME = 'Your App Name'\nSHOPIFY_APP_API_KEY = os.environ.get('SHOPIFY_APP_API_KEY')\nSHOPIFY_APP_API_SECRET = os.environ.get('SHOPIFY_APP_API_SECRET')\nSHOPIFY_APP_API_SCOPE = ['read_products', 'read_orders']\n# Find API version to pin at https://help.shopify.com/en/api/versioning\nSHOPIFY_APP_API_VERSION = \"0000-00\"\nSHOPIFY_APP_IS_EMBEDDED = True\nSHOPIFY_APP_DEV_MODE = False\n\n# Use the Shopify Auth authentication backend as the sole authentication backend.\nAUTHENTICATION_BACKENDS = (\n 'shopify_auth.backends.ShopUserBackend',\n)\n\n# Add the Shopify Auth template context processor to the list of processors.\n# Note that this assumes you've defined TEMPLATE_CONTEXT_PROCESSORS earlier in your settings.\nTEMPLATE_CONTEXT_PROCESSORS += (\n 'shopify_auth.context_processors.shopify_auth',\n)\n\n# Use the Shopify Auth user model.\nAUTH_USER_MODEL = 'auth_app.AuthAppShopUser'\n\n# Set the login redirect URL to the \"home\" page for your app (where to go after logging on).\nLOGIN_REDIRECT_URL = '/'\n\n# Set secure proxy header to allow proper detection of secure URLs behind a proxy.\n# This ensures that correct 'https' URLs are generated when our Django app is running behind a proxy like nginx, or is\n# being tunneled (by ngrok, for example).\nSECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')\n\n# For Django>=2.1, if you are using ngrok or other tools for tunnelling/proxying when developing,\n# we must explicitly allow cookies from different sites or the auth redirection after the login will\n# result in an infinite loop (session cannot be read from cookies)\nSESSION_COOKIE_SAMESITE = False\n```\n\nNote that in the example above, the application API key and API secret are pulled from environment settings, which is a\nbest practice for Django apps that helps avoid the accidental check-in of sensitive information to source files.\n\nSet `SHOPIFY_APP_IS_EMBEDDED` to `True` if your app has been configured as an Embedded app (you choose this option at\nthe time of app creation). Setting this will make the app provide a Javascript-based redirect that breaks out of an\nembedded app's `