跳转到主要内容

未知

项目描述

Django OAuth Backend 是一组 Django 模型,用于在服务器端实现 OAuth 协议。这些模型可以与各种实现协议HTTP部分的其它项目一起使用。其中一个项目是 lazr.authentication

用法

用法非常简单。

首先是将此应用程序添加到Django的 INSTALLED_APPS 列表

INSTALLED_APPS = (
    ...
    'oauth_backend'
)

接下来是与 OAuth 协议提供商集成,如 lazr.authentication。看起来可能像这样

# 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"
)

历史

此代码是从Canonical Identity Provider项目提取出来的。尽管已经额外努力确保所有依赖项都已破坏,并且此代码完全独立,但仍有可能遗漏了一些小问题。在这种情况下,请在项目的错误页面上报告这些错误。

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装软件包的更多信息。

源分布

django-oauth-backend-0.2.3.tar.gz (6.3 kB 查看散列)

上传时间

支持