saml2.0的服务提供程序实现。
pysamlsp的Python项目详细描述
pysamlsp是一个python库,用于在saml2.0 sso环境中实现服务提供者。
此软件包正在积极开发中,但目前尚未完成。请不要试图使用它。
要求
python包
- python设置工具
- Python2.7
- lxml
对于测试:
- 鼻子
- 预期值
- 丁格斯
非python包
- xmlsec1
- openssl(尽管xmlsec1可以用gnutls、libgcrypt或nss构建)
- libxml2
- libxslt
安装
在这个开发阶段,我还没有上传到Pypi一旦我有了,安装将像:
pip install pysqlsp
同时,您可以克隆此存储库并运行:
python setup.py install
用法
使用配置字典初始化类:
sp_config = dict( ... )
配置字典可能包含以下条目:
- ‘assertion_consumer_service_url’: The URL of the SSO provider.
- ‘issuer’: A unique identifier for the service provider; probably should match the entityID attribute of the SP metadata.
- ‘private_key’: A path for the private key PEM file, required for signing AuthnRequests.
- ‘sign_authnrequests’: True / False flag to indicate whether AuthnRequests should be signed.
- ‘certificate’: A path for the certificate file against which a SAMLResponse signature can be verified.
使用samlrequest查询参数创建重定向url:
sp = Pysamlsp(sp_config) redirect_url = sp.redirect_for_idp()
标识提供程序将投递到service providers metadata.xml中指定的地址。发布字段“samlResponse”将包含(base64encoded,gzip'd)XML响应:
saml_response = query['SAMLResponse'] if sp.idp_response_is_valid(saml_response): ...
签名的authnrequests
如果要签署authnrequests,则需要rsa私钥。下面是使用openssl创建密钥的过程
创建私钥,有效期10年:
openssl req -x509 -days 3650 -newkey rsa:1024 -keyout saml_key_pw.pem -out saml.crt
从新密钥中删除密码短语。此库当前不支持带有密码短语的密钥:
openssl rsa -in saml_key_pw.pem -out saml_key.pem
从私钥创建公钥。您将需要此元数据:
openssl rsa -in saml_key.pem -pubout > saml.pub