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)
- 首次发布