Skip to main content

A Sample Django application for exchanging tokens with Instagram Basic Display API

Project description

django-social-connector

A sample Django app for OAuth Token Exchange to support Instagram Basic Display API.

[!CAUTION] This app is not meant for production. It lacks certain security features and certain customization options which must be implemented based on the exact use case. It will only work in DEBUG mode, for development.

Use this app for development only and as a guide for adding your own token exchange backend endpoint.

Adding to Django:

  1. Install from PyPi: pip install django-social-connector

  2. Add to INSTALLED_APPS:

# settings.py
INSTALLED_APPS = [
    # ...
    "social_connector",
    # ...
]
  1. Add INSTAGRAM_APP_ID and INSTAGRAM_SECRET settings:
# settings.py
import os

INSTAGRAM_APP_ID = os.environ.get("INSTAGRAM_APP_ID")
INSTAGRAM_SECRET = os.environ.get("INSTAGRAM_SECRET")

Note: Your INSTAGRAM_SECRET should be loaded and stored as a secret key. How to do that properly is outside the scope of this guide and depends on your environment.

  1. Add a token endpoint to your URLs:
# urls.py
from django.urls import path
from social_connector.views import ig_token

urlpatterns = [
    # ...
    path('ig_token/', ig_token, name="ig_token"),
    # ...
]

You can customize the path and the name as needed.

  1. The endpoint is ready for use in development.

Troubleshooting

CORS Settings

Make sure your frontend host is allowed for CORS requests in Django.

Moving to Production

This app is for demonstration and development use only.

For production, create your own view in your own codebase.

For being Production ready, the endpoint should have at least the following additional safeguards:

  • CSRF protection
  • Throttling (limited amount of requests per user per time)
  • Further input checks and sanitation before sending the API request to Instagram
  • Might require the user being logged in, depending on the specific app's use case

Adding these features will bloat this minimal sample, especially when trying to reduce requirements. Implementation of some of these features also depend on your specific use case.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-social-connector-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_social_connector-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file django-social-connector-0.1.0.tar.gz.

File metadata

  • Download URL: django-social-connector-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for django-social-connector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 573b63c4954be96907e64d26bbae0146146a67dc232c3c88e93d936e92e8b404
MD5 ca77d928bcd42a31e7839e12a6cba6f6
BLAKE2b-256 1dab5f7d92368ba695dd034db4fbc113ed42a2fd919c3a5f371caba41d20bb7a

See more details on using hashes here.

File details

Details for the file django_social_connector-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_social_connector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2e1aaf2bbc69e4fc4515aacb3782131741169d1e50701d80489060c527f87e3
MD5 07869a08146c84486b94bbbfd758bb12
BLAKE2b-256 27d6be679098f3f8ce898b8ef37ccaa23113dbc24e5e6451dc70db326caaa9b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page