django openid connect(oidc)身份验证后端
django-oidc-tf的Python项目详细描述
此模块使在django项目中集成openid connect作为身份验证源变得容易。
在幕后,它使用罗兰·赫德伯格(Roland Hedberg)伟大的结节病图书馆。
由Jhuapl boss修改以支持python3
由thomas fróssman修改,包括修复和附加修改。
快速启动
安装djangooidc:
# Latest (pre) release pip install django-oidc-tf # Latest code - unstable! pip install git+https://github.com/thomasf/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广告操作将是:
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/"], } } }
现在可以通过转到(在开发服务器上)或任何 需要验证的视图。
功能
- 准备使用Django身份验证后端
- 数据库中没有存储任何模型-只是在settings.py中进行一些配置,以使其保持简单
- 与Django的内部帐户和权限系统完全集成
- 支持所有oidc工作流:授权代码流、隐式流、混合流。不知道就别担心 这些是什么-这个包有很好的默认值。
- 包括在提供商级别注销
历史记录
0.1.0(2015-05-08)
- 首次发布