{"id":24360610,"url":"https://github.com/stlk/django-shopify-auth","last_synced_at":"2025-10-25T16:09:32.814Z","repository":{"id":14451588,"uuid":"17163252","full_name":"stlk/django-shopify-auth","owner":"stlk","description":"A package for adding Shopify authentication to a Django app.","archived":false,"fork":false,"pushed_at":"2025-01-17T08:49:36.000Z","size":188,"stargazers_count":149,"open_issues_count":2,"forks_count":54,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-28T06:08:45.283Z","etag":null,"topics":["django","shopify"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stlk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-02-25T06:05:12.000Z","updated_at":"2025-03-14T18:15:02.000Z","dependencies_parsed_at":"2024-01-24T22:04:44.042Z","dependency_job_id":"4ef7f7db-a7ca-4448-93ef-0b1d24b3996d","html_url":"https://github.com/stlk/django-shopify-auth","commit_stats":{"total_commits":177,"total_committers":16,"mean_commits":11.0625,"dds":0.4011299435028248,"last_synced_commit":"73fb6bfbb1576117f7805ac979f7b4a3c6736851"},"previous_names":["stlk/django-shopify-auth","discolabs/django-shopify-auth"],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stlk%2Fdjango-shopify-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stlk%2Fdjango-shopify-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stlk%2Fdjango-shopify-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stlk%2Fdjango-shopify-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stlk","download_url":"https://codeload.github.com/stlk/django-shopify-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135144,"owners_count":20889421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","shopify"],"created_at":"2025-01-18T21:37:06.524Z","updated_at":"2025-10-25T16:09:27.777Z","avatar_url":"https://github.com/stlk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"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![example workflow](https://github.com/discolabs/django-shopify-auth/actions/workflows/ci.yml/badge.svg)\n\nThis Django package makes it easy to integrate Shopify authentication into your Django app.\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 token-based authentication flow for Embedded Shopify apps.\n\nEmbedded vs Standalone apps\n--------------\n\nSession token-based authentication is now required for embedded apps. Support for it is implemented in [separate app](shopify_auth/session_tokens/). Read [this](https://shopify.dev/apps/getting-started/app-types#embedded-apps) if you're not sure what approach to use.\n\nRequirements\n------------\nTests are run against Django versions defined in `.github/workflows/ci.yml`. This package may work for\nother Django versions but it's not guaranteed.\n\nYou'll need a [Shopify partner account](http://shopify.com/partners) and to have created an app in order to get an API key and secret.\n\n\nPackage Installation and Setup - Standalone app\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\n\n### 1. Install package\nInstallation is super easy via `pip`:\n\n```shell\n\u003e 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\nBefore moving forward, ensure this model has been added to the database by running\n```\npython manage.py makemigrations\npython manage.py migrate\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_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\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\nSetting `SHOPIFY_APP_DEV_MODE` to `True` allows you to test your apps locally by skipping the external OAuth phase for\nyour app. As it means you can log into your app as any store, you should obviously ***never*** set this to `True` in\nproduction.\n\nNow that all of the settings are configured, you can run `migrate` to set up the database for your new user model:\n\n```shell\n\u003e python manage.py migrate\n```\n\n\n### 4. Configure URL mappings\n\nInclude `shopify_auth` URLs in your project's `urls.py`:\n\n```python\n# urls.py\nfrom django.urls import include, path\n\nurlpatterns = [\n    path('login/', include('shopify_auth.urls')),\n\n    # ... remaining configuration here ...\n]\n```\n\n### 5. Create application views\nNow that you've gotten the configuration out of the way, you can start building your application.\n\nAll views inside your application should be decorated with `@login_required`.\nThis decorator will check that a user has authenticated through the Shopify OAuth flow.\nIf they haven't, they'll be redirected to the login screen.\n\n```python\nfrom django.shortcuts import render\nfrom shopify_auth.decorators import login_required\n\n@login_required\ndef home(request, *args, **kwargs):\n    return render(request, \"my_app/home.html\")\n```\n\n### 6. Making Shopify API calls\nTo make Shopify API calls on behalf of a user, we can use the user's `session` property inside a `with` statement:\n\n```python\ndef view(request, *args, **kwargs):\n\n    # Get a list of the user's products.\n    with request.user.session:\n        products = shopify.Product.find()\n\n    # ... remaining view code ...\n```\n\nBehind the scenes, using `with request.user.session` sets up a temporary Shopify API session using the OAuth token we\nobtained for that specific user during authentication.\n\nAll code wrapped within the `with` statement is executed in the context of the specified user. You should always wrap\ncalls to the Shopify API using this pattern.\n\n\nPartner Application Setup\n-------------------------\nIn addition to getting the package up and running in your local Django project, you'll need to configure your\napplication via the Shopify Partner dashboard.\n\nTo avoid getting an OAuth error while customers try to install your application, make sure your application's settings\ninclude the absolute URL to `/login/finalize/` (including the trailing slash) in their whitelisted URLs. For example,\nif your application resides at `https://myapp.example.com`, then you should include\n`https://myapp.example.com/login/finalize/` in the \"Redirection URL\" section of your application settings.\n\n\nQuestions or Problems?\n----------------------\n\nRead up on the possible API calls:\n\u003chttps://shopify.dev/\u003e\n\nAsk technical questions on Stack Overflow:\n\u003chttps://stackoverflow.com/questions/tagged/shopify\u003e\n\n\nRelease History\n---------------\n\nRefer to the [change log](https://github.com/discolabs/django-shopify-auth/blob/master/CHANGELOG.md) for a full list of changes.\n\nSpecial Thanks\n--------------\n\nA big shout-out to [Josef Rousek](https://github.com/stlk) for his contributions and help maintaining this package.\n\nWork with us!\n------------------\n\nIf you want to work with Django and maybe even React, the current maintainer [Digismoothie.com is hiring](https://www.digismoothie.com/company/careers).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstlk%2Fdjango-shopify-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstlk%2Fdjango-shopify-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstlk%2Fdjango-shopify-auth/lists"}