django openid connect(oidc)身份验证后端

django-oidc的Python项目详细描述


此模块使在django项目中集成openid connect作为身份验证源变得容易。

在幕后,它使用罗兰·赫德伯格(Roland Hedberg)伟大的结节病图书馆。

快速启动

安装djangooidc:

# Latest released package:
pip install django-oidc

# Latest code - unstable!
pip install git+https://github.com/marcanpilami/django-oidc.git

然后要在django项目中使用它,请将其添加到您的url.py:

url(r'openid/', include('djangooidc.urls')),

然后将以下项目添加到您的设置中。py:

  • 在默认值之后将“djangooidc.backends.openidconnectbackend”添加到身份验证后端'django.contrib.auth.backends.modelbackend'

  • 设置登录url='openid'

  • 添加特定的oidc参数(更改您的绝对url):

    # Information used when registering the client, this may be the same for all OPs
    # Ignored if auto registration is not used.
    OIDC_DYNAMIC_CLIENT_REGISTRATION_DATA = {
        "application_type": "web",
        "contacts": ["ops@example.com"],
        "redirect_uris": ["http://localhost:8000/openid/callback/login/", ],
        "post_logout_redirect_uris": ["http://localhost:8000/openid/callback/logout/", ]
    }
    
    # Default is using the 'code' workflow, which requires direct connectivity from your website to the OP.
    OIDC_DEFAULT_BEHAVIOUR = {
        "response_type": "code",
        "scope": ["openid", "profile", "email", "address", "phone"],
    }
    

上面的配置足以使用支持发现和自客户端注册的oidc提供程序(op)。 此外,您可能需要使用一个特定的openid连接提供程序,它不是自动发现的。完成了 通过将项添加到oidc\u providers字典。有关参数名称,请参阅完整文档。

例如,azure ad op(v1端点,因为v2还不支持代码流)将是:

OIDC_PROVIDERS = {
    "Azure Active Directory": {
        "srv_discovery_url": "https://sts.windows.net/aaaaaaaa-aaaa-1111-aaaa-xxxxxxxxxxxxx/",
        "behaviour": OIDC_DEFAULT_BEHAVIOUR,
        "client_registration": {
            "client_id": "your_client_id",
            "client_secret": "your_client_secret",
            "redirect_uris": ["http://localhost:8000/openid/callback/login/"],
            "post_logout_redirect_uris": ["http://localhost:8000/openid/callback/logout/"],
            "token_endpoint_auth_method": "client_secret_post",
        }
    }
}

现在可以通过转到(在开发服务器上)或任何 需要验证的视图。

功能

  • 准备使用Django身份验证后端
  • 数据库中没有存储任何模型-只是在settings.py中进行一些配置,以使其保持简单
  • 与Django的内部帐户和权限系统完全集成
  • 支持所有oidc工作流:授权代码流、隐式流、混合流。不知道就别担心 这些是什么-这个包有很好的默认值。
  • 包括在提供商级别注销

历史记录

0.1.4(2017-01-07)

  • OIDC库已更新。它的版本不再是“最新的”,以避免在每次主要的库更新时破坏djangoodic。
  • 已修复更新损坏的代码。
  • 不再需要窗户上的轮子了。

0.1.0(2015-05-08)

  • 首次发布

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaSpring重定向请求处理程序   SwingJava:拆分字符串并将其放入文本区域的   Java:标记“”上出现语法错误,此标记后面应为表达式   web服务Java RestService从日志文件写入和读取数据   java如何将ArrayList<String>转换为char数组,然后向后打印每个单词?   java SimpleDataFormat解析返回年终日期   加密Java aes解密bytebuffer,包括填充为空字节   java有没有办法从特定的if语句调用变量?   java从更新返回到渲染   spring GRPC Java登录测试   java为什么下面的代码不工作(StringBuffer.toString!=null)   java是一种可行的模式吗?   使用Spring集成测试的JavaOSGi片段   java jCommander为未知和未使用的值引发异常?   在imageView的editText中输入的java图像URL