用于django包装onelogin的python saml包的saml2身份验证后端https://github.com/onelogin/python-saml

django-saml2-pro-auth的Python项目详细描述


[![PYPI版本](https://img.shields.io/PYPI/v/django-saml2-pro-auth.svg)(https://pypi.org/project/django-saml2-pro-auth/)[![Github许可证](https://img.shields.io/badge/license mit blue.svg)](https://raw.githubusercontent.com/mindpointgroup/django-saml2-pro-auth/master/license)

[![覆盖状态](https://coveralls.io/repos/github/mindpointgroup/django-saml2-pro-auth/badge.svg?branch=master)](https://coveralls.io/github/mindpointgroup/django-saml2-pro-auth?branch=master)[![Circleci](https://circleci.com/gh/mindpointgroup/django-saml2-pro-auth.svg?style=svg)(https://circleci.com/gh/mindpointgroup/django-saml2-pro-auth)



![Python版本](https://img.shields.io/pypi/pyversions/django-saml2-pro-auth.svg)[![django版本](https://img.shields.io/badge/django-1.8%2c%201.10%2c%201.11-44b78b.svg)(https://pypi.org/project/django-saml2-pro-auth/)

[![下载](http://pepy.tech/badge/django-saml2-pro-pro-auth)(http://pepy.tech/badge/django-saml2-pro-auth)



















<

<
;先决条件

在操作系统上,必须安装libxml、xmlsec1和openssl(可用的开发包)。软件包名称会因操作系统而异。

例如,在ubuntu上,先决条件软件包名称是"build essential libssl dev libffi dev python dev libxml2 dev libxmlsec1 xmlsec1 libxmlsec1 openssl libxmlsec1 dev`

Hon 2**

``bash
pip安装django-saml2-pro-auth
`````

**python 3**

``bash
``pip3安装django-saml2-pro-auth
```


向下滚动阅读每个选项



``python

myprovider"{
"email":dict(key="email",输入dex=0),
"name":dict(key="username",index=0)
}






saml_providers=[{
"myprovider":{
"strict":true,
"debug":false,
"custom_base_path":",
"sp":{
"entityid":"https://test.davila.io/sso/saml/metadata",
"断言"sumerservice"{
"url":"https://test.davila.io/sso/saml/?acs",
"binding":"urn:oasis:names:tc:saml:2.0:bindings:http-post"
},
"singlelogoutservice":{
"url":"https://test.davila.io/sso/saml/?sls",
"binding":"urn:oasis:names:tc:saml:2.0:bindings:http redirect"
},
"nameid format":"urn:oasis:names:tc:saml:1.1:nameid format:unspecified",
对于cert/key,可以将它们的内容放在
x509cert和privatekey参数
中作为single-l行字符串或将它们放入
certs/sp.key和certs/sp.crt中,或者您可以通过自定义的base路径提供一个
觰路径,该路径应包含
sp.crt和sp.key
"x509cert":",
"privatekey":",
},
"idp":{
"entityid":"https://kdfjdfsmyprovider.com/0f3172cf-5aa6-40f4-8023-baf9d09996cec",
"SingleSignonService":"url":"http://kdkdfjdffsklj.my.myprovider.com/applogin/appkey/0f3172cf-5aa6-40f4-8023-baf9d09996cec/customerid/kdkdkdfjdffsklj",
"binding":"urn:oasis:oasis:names:tc:saml:2.0:bindings:http-redirect"
"singleSignonservice服务":"url":"url":"url":"http://http://kdkdkdkdkdfffjdfjdffskj/>},
"单一登录服务":{
"url":"https://kdkdfjdfsklj.my.myprovider.com/applogout",
"binding":"urn:oasis:names:tc:saml:2.0:bindings:http redirect"
},
"x509cert":open(os.path.join(base_dir,'certs/myprovider.crt'),'r').read(),
},
"organization":{
"en-us":{
"name":"example inc",
"displayname":"example incorporated",
"url":"example.com"
}
},
"联系人":{
"技术":{
"给定名称":"Jane Doe",
"电子邮件地址":"jdoe@examp.com"
},
"支持":{
"给定名称":"Jane Doe",
"电子邮件地址":"jdoe@examp.com"
}
},
"安全性":{
"名称加密":false,
"authnrequestssigned":true,
"logoutrequestsigned":false,
"logoutresponsesigned":false,
"signmetadata":false,
"wantmessagessigned":false,
"wantasserionssigned":true,
"wantnameid":true,
"wantnameidencrypted":false,
"wantasserionsencrypted":true,
"signaturealgorithm":"http://www.w3.org/2000/09/xmldsig rsa-sha1",
"digestalgorithm":"http://www.w3.org/2000/09/xmldsig rsa-sha1",
}
}
}
}
}```

**身份验证后端:**与示例完全相同,这是必需的。它告诉django将其用作有效的身份验证机制。

**saml_route(可选,默认值为/sso/saml/):**这告诉django在哪里执行所有与saml相关的活动。默认路由是/sso/saml/。您仍然需要在自己的"url.py"中包含源url。例如:

`` python
来自django.conf.urls import include,url
来自django.contrib import admin
来自django.conf import settings
来自django.conf.urls.static import static
导入配置文件。url
导入帐户。url
将django_saml2_pro_auth.urls导入为saml_url

来自。导入视图

urlpatterns=[
url(r'^$',views.homepage.as懔view(),name='home'),
url(r'^about/$',views.aboutpage.as懔view(),name='about'),
url(r'^users/',include(profiles.url,namespace='profiles'),
url(r'^admin/',include(admin.site.url)),
url(r'^',include(accounts.url s,namespace="accounts'),
url(r'^',include(saml戋urls,namespace="saml'),
]

````
因此,首先通过"import django戋u saml2戋u pro戋auth.urls作为saml戋urls"导入url(是否命名由您决定)。然后通过'url(r'^',include(saml_url,namespace='saml')将其添加到模式中。此示例将为您提供此身份验证后端提供的默认路由。

**saml_redirect(可选,默认值为none):**这将告诉身份验证后端在用户通过idp登录后将其重定向到何处。**注意**:大多数用户不需要这样做。优先顺序是:saml_redirect value(如果定义了)、saml响应中提供的relay_state,而回退只是转到应用程序的根路径。

**saml_fail_redirect(可选,默认值为none):**这告诉身份验证后端当saml可信时重定向的位置。在Django方面失败了。当使用提供的后端时,当用户在django db中被标记为is_active=false而仍能够使用idp进行身份验证时,可能会发生这种情况。当saml_fail廑u redirect尚未设置时,将引发samlerror以避免重定向循环。

**saml廑u users廑u map(必需):**这使得可以将来自idp的属性映射到属于django用户模型的属性中。有几种方法可以定义它。dict键(左侧)是用户模型中定义的属性,dict值(右侧)是属性正如idp所提供的。

`` python

"email":"email",
"name":"username
}
}
`````

>有时,idps可能会以数组的形式提供值(即使它实际上应该只是一个字符串)。这个软件包也支持这一点。例如,假设idp提供的用户属性具有以下数据结构:
`{"email":["foo@example.com"],"username":"foo"}`
您只需使键稍微复杂一些,其中"key"是键,"index"表示所需值所在的索引。如下所示:

`` python
saml_users_map=[{
"myidp":{
"email":{"key":"email","index":0},
"name":"username
}
```

,当然,即使idp提供的属性不是数组,也可以使用dict结构。例如:

``python
saml庘u users庘map=[{
"myidp":{
"email":{"key":"email"},
"name":{"key":"username"}
}
````

****saml庘u users庘u lookup庘属性(可选):**
指定用于在数据库中查找对象的用户模型字段se.
必须是"saml_user s_map"中指定的django用户模型的dict键之一。

django用户模型中的属性应设置"unique"标志。
(在django的默认用户模型中,只有username在db中具有唯一的contstraint,可以使用相同的电子邮件d按多个用户)


默认为"用户名"

``python
saml_users_lookup_attribute="email"
```

**saml_users_sync_attributes(可选):**
指定每次登录时是否必须使用从idp接收到的用户属性更新用户属性。

false

`` python
saml_users_sync_attributes=true
````


**saml_users_strict_mapping(可选):**
指定saml_user_map中定义的每个用户属性是否必须存在于saml响应中


默认为true

`` python
saml_users_严格映射=false
```

ue for is_superuser and is_staff to false
saml_users_strict_mapping=false
saml_users_map=[{
"myprovider":{
"email":dict(key="email",index=0),
"username":dict(key="username",index=0),
"is_superuser":dict(key="is_superuser",index=0,default=false),
"is_staff":dict(key="is_staff",index=0,default=false)
}
}
````

**saml戋providers:*这与onelogin的[python saml和python3 saml包](https://github.com/onelogin/python3 saml设置)完全相同。最大的区别在于,这里提供了一个dict列表,其中最上面的键必须映射1:1到"saml_users_map"中最上面的键。此外,此包还允许您通过"open()"调用引用证书/密钥文件。这是为了允许拥有多个外部客户的用户使用任意N个IDP登录到您的平台。




|
--————————————————————————————————————————————————————--————————————————————————————————————————————————————————————————————————acs&;provider=myprovider`断言使用者服务终结点。这是你的国内流离失所者将张贴断言。"provider"查询字符串的值必须与saml_providers设置的顶级键匹配。|
`/sso/saml/元数据?provider=myprovider`这是SP(即您的django应用程序)具有元数据的地方。一些idp请求此项以生成配置。"provider"查询字符串的值必须与saml_providers设置的顶级键匹配。|
`/sso/saml/?provider=myprovider`要触发SP启动的登录时使用此终结点。例如,这可以是"login with clientx okta"按钮的"ref"。|

这里有一些提示。

*确保sp`entityid`配置的值与idps配置中提供的值匹配。
*idp可能默认为特定的签名类型,通常"断言"或"响应"是选项。根据您定义saml提供程序配置的方式,它将指示该值应该是什么。

使用完全模拟saml交互的ation测试来测试实际的后端身份验证
*测试为idp和sp的身份验证后端
*模型(具有多点支持)中的视图和authenticate()get_user()方法添加覆盖范围,以便通过django admin进行管理
*测试/支持Django 2的ORT



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

推荐PyPI第三方库


热门话题
Java类之间并发性不一致的HashMap   插件如何在JavaSwing中使用UIManager和Classloader从外部jar安装外观?   java JasperReports:找不到子报表   在项目中找不到java生成的Javadoc文件   java BigDecimal。multiply()和divide()方法返回十六进制数。为什么?   java统计出现次数并从字符串中删除重复项   调用运算符时发生java NullPointerException   Spring和Hibernate之间的java配置错误   JavaZK将用户重定向回上一页   Javasocket为传出连接指定特定的网络接口   如果拖动到某个区域外,java Make按钮操作将被取消   如何在Eclipse for selenium 3.141.59中添加Java文档链接   java从匹配条件的数组中获取所有索引   docker未连接到RemoteWebDriver的java Gitlab ci selenium测试   java重写run方法   utf 8如何使用java解码UTF8编码的字符串?   java如何从eclipse调试部署在tomcat上的web应用程序?   将字母字符与前面没有百分号的Java正则表达式匹配