Skip to main content

UNKNOWN

Project description

Django OAuth Backend is a set of Django models which are required for implementing OAuth protocol on the server side. Those models can be used together with various other projects which implement HTTP part of the protocol. One such projects is lazr.authentication.

Usage

Usage is quite simple.

First thing is to add this application to Django’s INSTALLED_APPS list:

INSTALLED_APPS = (
    ...
    'oauth_backend'
)

Next is to integrate it with OAuth protocol provider, like lazr.authentication. It will look something like that:

# Application's WSGI file
from django.core.handlers.wsgi import WSGIHandler
from lazr.authentication.wsgi import OAuthMiddleware
from oauth_backend.models import DataStore, Consumer, Token


def oauth_authenticate(oauth_consumer, oauth_token, parameters):
    try:
        consumer = Consumer.objects.get(
            user__username=oauth_consumer.key
        )
        token = Token.objects.get(token=oauth_token.key)
        if token.consumer.key == oauth_consumer.key:
            return consumer.user
    except (Token.DoesNotExist, Consumer.DoesNotExist):
        return None


django = WSGIHandler()
application = OAuthMiddleware(
    django,
    authenticate_with=oauth_authenticate,
    data_store=DataStore(),
    protect_path_pattern="/protected"
)

History

This code was extracted from Canonical Identity Provider project. Although an extra effort was made to make sure that all dependencies are broken and this code is fully independent, it’s conceivable that some small things were missed. In that case please report those bugs on the project’s bug page.

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-oauth-backend-0.2.3.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file django-oauth-backend-0.2.3.tar.gz.

File metadata

File hashes

Hashes for django-oauth-backend-0.2.3.tar.gz
Algorithm Hash digest
SHA256 5e0c49dc1b5f289e9cae3042992f750f6bace6f0c01da9c0cac1849c8651b0e2
MD5 6e275d127ed7cabc86a3e6e8381a09ad
BLAKE2b-256 2f0692bf0e3754f9d5fddb111f222a6b5b486eb4c31784da0b5ef17aabc3e9eb

See more details on using hashes here.

Supported by

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