The django-smart-proxy app allows you to configure plug-and-play reverse proxy solutions for social networks and other complex integration points with your website.
Project description
[![Latest Version](https://pypip.in/version/django-smart-proxy/badge.svg)](https://pypi.python.org/pypi/django-smart-proxy/)
[![Downloads](https://pypip.in/download/django-smart-proxy/badge.svg)](https://pypi.python.org/pypi/django-smart-proxy/)
Django Smart Proxy
==================
Django Smart Proxy is a plug-and-play solution for implementing pass-through proxies in
a Django-based environment.
**Extensibility**<br/>
Django Smart Proxy exposes a *request_decorators* parameter that makes it easily
extensible, allowing access to the request "pipeline" before being sent to the host.
**Common Use Cases**
- Handling OAuth on the server-side to avoid exposing secret keys to the client.
- As an alternative to CORS for making cross-domain AJAX requests.
- Anything else...?
Installation
============
**Requires**
- Python >= 2.6 (supports up to 3.4)
- Django >= 1.4 (Python 2 support up to 1.6.x)
*For all requirements, see <a href="https://github.com/celerityweb/django-smart-proxy/blob/master/setup.py" target="_blank">setup.py</a>.*
**Installing**
```
pip install django-smart-proxy
```
Usage
=====
1. Add ```smart_proxy``` to ```INSTALLED_APPS``` in your ```settings.py```.
**Example**
```python
INSTALLED_APPS = (
...,
'smart_proxy',
...,
)
```
2. Add a ```SMART_PROXIES``` dictionary to ```settings.py``` to configure an arbitrary number of proxies.
**Example**
```python
SMART_PROXIES = {
'instagram': {
'host_endpoint': 'https://api.instagram.com/v1/',
'allowed_methods': ('get', 'put', 'post', 'delete',),
'timeout': 60.0,
},
'twitter': {
'host_endpoint': 'https://api.twitter.com/1.1/',
'allowed_methods': ('get', 'put', 'post', 'delete',),
'timeout': 60.0,
'request_decorators': (
'channel.apps.twitter_auth.utils.append_authorization_header',
),
},
}
```
3. Edit your ```urls.py``` to configure a root URL mapping for the proxies.
**Example**
```python
urlpatterns = patterns(
...,
url(r'^proxy/', include('smart_proxy.urls')),
...,
)
```
4. If applicable, provide an implementation for your request decorators.
**Example**
```python
from django.conf import settings
from requests_oauthlib import OAuth1
def append_authorization_header(request, session):
"""
This function decorates requests to the Twitter proxy with a
signed oauth-compliant Authorization header.
"""
client_key = getattr(settings, 'SOCIAL_AUTH_TWITTER_KEY', None)
client_secret = getattr(settings, 'SOCIAL_AUTH_TWITTER_SECRET', None)
if client_key and client_secret:
request.auth = OAuth1(
client_key,
client_secret=client_secret,
resource_owner_key=session.get('twitter_oauth_token'),
resource_owner_secret=session.get('twitter_oauth_token_secret'))
return request
```
5. You're Done!
In this example, your proxies will be available at ```/proxy/instagram/``` and ```/proxy/twitter/``` respectively.
[![Downloads](https://pypip.in/download/django-smart-proxy/badge.svg)](https://pypi.python.org/pypi/django-smart-proxy/)
Django Smart Proxy
==================
Django Smart Proxy is a plug-and-play solution for implementing pass-through proxies in
a Django-based environment.
**Extensibility**<br/>
Django Smart Proxy exposes a *request_decorators* parameter that makes it easily
extensible, allowing access to the request "pipeline" before being sent to the host.
**Common Use Cases**
- Handling OAuth on the server-side to avoid exposing secret keys to the client.
- As an alternative to CORS for making cross-domain AJAX requests.
- Anything else...?
Installation
============
**Requires**
- Python >= 2.6 (supports up to 3.4)
- Django >= 1.4 (Python 2 support up to 1.6.x)
*For all requirements, see <a href="https://github.com/celerityweb/django-smart-proxy/blob/master/setup.py" target="_blank">setup.py</a>.*
**Installing**
```
pip install django-smart-proxy
```
Usage
=====
1. Add ```smart_proxy``` to ```INSTALLED_APPS``` in your ```settings.py```.
**Example**
```python
INSTALLED_APPS = (
...,
'smart_proxy',
...,
)
```
2. Add a ```SMART_PROXIES``` dictionary to ```settings.py``` to configure an arbitrary number of proxies.
**Example**
```python
SMART_PROXIES = {
'instagram': {
'host_endpoint': 'https://api.instagram.com/v1/',
'allowed_methods': ('get', 'put', 'post', 'delete',),
'timeout': 60.0,
},
'twitter': {
'host_endpoint': 'https://api.twitter.com/1.1/',
'allowed_methods': ('get', 'put', 'post', 'delete',),
'timeout': 60.0,
'request_decorators': (
'channel.apps.twitter_auth.utils.append_authorization_header',
),
},
}
```
3. Edit your ```urls.py``` to configure a root URL mapping for the proxies.
**Example**
```python
urlpatterns = patterns(
...,
url(r'^proxy/', include('smart_proxy.urls')),
...,
)
```
4. If applicable, provide an implementation for your request decorators.
**Example**
```python
from django.conf import settings
from requests_oauthlib import OAuth1
def append_authorization_header(request, session):
"""
This function decorates requests to the Twitter proxy with a
signed oauth-compliant Authorization header.
"""
client_key = getattr(settings, 'SOCIAL_AUTH_TWITTER_KEY', None)
client_secret = getattr(settings, 'SOCIAL_AUTH_TWITTER_SECRET', None)
if client_key and client_secret:
request.auth = OAuth1(
client_key,
client_secret=client_secret,
resource_owner_key=session.get('twitter_oauth_token'),
resource_owner_secret=session.get('twitter_oauth_token_secret'))
return request
```
5. You're Done!
In this example, your proxies will be available at ```/proxy/instagram/``` and ```/proxy/twitter/``` respectively.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-smart-proxy-0.2.1.tar.gz
.
File metadata
- Download URL: django-smart-proxy-0.2.1.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1f9f8b4ab7fc17bf9b0d4e4f68a45dec25bad5c4f0831d2d1ac86e4304e6e48 |
|
MD5 | 2f9e80bcbab2204ab669be44fa79c94a |
|
BLAKE2b-256 | 615f5f35bea47a00250db084f509da9b86ca9f1c344c8c8d280e3348d94250d6 |
File details
Details for the file django-smart-proxy-0.2.1.macosx-10.9-x86_64.tar.gz
.
File metadata
- Download URL: django-smart-proxy-0.2.1.macosx-10.9-x86_64.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 487ed262825db20c5d767ae665d1a70ebd12b2f62d712f13889850aa7588ca3e |
|
MD5 | ff55feb148993bfa12a89927309d9444 |
|
BLAKE2b-256 | 932baa41e8e2f5fc0c1b81f8404b1789b053af400390885ae2bac0110ee4917d |