ID4me协议的Python客户端库 - 依赖方。见:https://id4me.org
项目描述
id4me-rp-client
Python依赖方客户端库,用于ID4me协议。有关协议的详细信息,请访问: https://id4me.org
库提供了与身份权威进行身份验证和从身份代理请求声明的依赖方功能。
规范参考
https://gitlab.com/ID4me/documentation/blob/master/id4ME%20Technical%20Specification.adoc
- 版本:1.0
- 修订:02
安装
pip install id4me-rp-client
使用
注册客户端并与身份权威进行授权
from id4me_rp_client import *
# these imports are just needed in this example
from builtins import input
import json
import uuid
registrations = dict()
# a routine to save client registration at authority
def save_authority_registration(auth_name, auth_content):
registrations[auth_name] = auth_content
pass
# a routine to load client registration at authority
def load_authority_registration(auth_name):
return registrations[auth_name]
# create client object with basic parameters of your app
client = ID4meClient(
get_client_registration=load_authority_registration,
save_client_registration=save_authority_registration,
app_type=OIDCApplicationType.web,
validate_url='https://dynamicdns.domainconnect.org/ddnscode',
client_name='Foo app',
logo_url='https://upload.wikimedia.org/wikipedia/commons/7/76/Foobar2000_logo_2014.png',
policy_url='https://foo.com/policy',
tos_url='https://foo.com/tos',
private_jwks_json=ID4meClient.generate_new_private_keys_set())
try:
# make a discovery of identity authority and register if needed
# find_authority and save_authority are optional, but when missing client will be registered each time anew
ctx = client.get_rp_context(
id4me='id200.connect.domains')
# get a link to login routine
link = client.get_consent_url(
ctx,
claimsrequest=ID4meClaimsRequest(
userinfo_claims={
OIDCClaim.name: ID4meClaimRequestProperties(reason='To call you by name'),
OIDCClaim.email: ID4meClaimRequestProperties(essential=True, reason='To be able to contact you'),
OIDCClaim.email_verified: ID4meClaimRequestProperties(reason='To know if your E-mail was verified'),
}),
state=str(uuid.uuid4())
)
print('Please open the link:\n{}'.format(link))
# Normally code will arrive as query param on client.validateUrl
code = input('Please enter code: ')
# Get ID token
id_token = client.get_idtoken(context=ctx, code=code)
print('ID Token:\n{}'.format(json.dumps(id_token, sort_keys=True, indent=4)))
# Get User Info
userinfo = client.get_user_info(context=ctx)
print('User Info:\n{}'.format(json.dumps(userinfo, sort_keys=True, indent=4)))
except ID4meException as e:
print('Exception: {}'.format(e))
输出
Resolving "_openid.id200.connect.domains."
Checking TXT record "v=OID1;iss=id.test.denic.de;clp=identityagent.de"
identity_authority = auth.freedom-id.de
registering with new identity authority (auth.freedom-id.de)
destination = https://auth.freedom-id.de/login?scope=openid&response_type=code&client_id=hmkzay2riyon4&redirect_uri=https%3A//foo.com/validate&login_hint=id200.connect.domains&state=&claims=%7B%22userinfo%22%3A%20%7B%22email_verified%22%3A%20%7B%22reason%22%3A%20%22To%20know%20if%20your%20E-mail%20was%20verified%22%7D%2C%20%22email%22%3A%20%7B%22reason%22%3A%20%22To%20be%20able%20to%20contact%20you%22%2C%20%22essential%22%3A%20true%7D%2C%20%22name%22%3A%20%7B%22reason%22%3A%20%22To%20call%20you%20by%20name%22%7D%7D%7D
Please open the link:
https://auth.freedom-id.de/login?scope=openid&response_type=code&client_id=hmkzay2riyon4&redirect_uri=https%3A//foo.com/validate&login_hint=id200.connect.domains&state=&claims=%7B%22userinfo%22%3A%20%7B%22email_verified%22%3A%20%7B%22reason%22%3A%20%22To%20know%20if%20your%20E-mail%20was%20verified%22%7D%2C%20%22email%22%3A%20%7B%22reason%22%3A%20%22To%20be%20able%20to%20contact%20you%22%2C%20%22essential%22%3A%20true%7D%2C%20%22name%22%3A%20%7B%22reason%22%3A%20%22To%20call%20you%20by%20name%22%7D%7D%7D
Please enter code: >? 9jNXCX9OZ4HQLr2YZWKisw.5mSDkoR-5YJQoTp3f1vuxg
User Info:
{
"aud": "hmkzay2riyon4",
"email": "foo@bar.de",
"email_verified": true,
"exp": 1538762218,
"iat": 1538761918,
"id4me.identifier": "id200.connect.domains",
"id4me.identity": "id200.connect.domains",
"iss": "https://auth.freedom-id.de",
"nbf": 1538761918,
"sub": "uiw3pTRRLVaKJqbnbSwr4EVuhEPTHvRgci91RbhYU2rab/YVDqDmqTKzTVAdDMm+",
"updated_at": 1538564738
}
请求自定义声明
为了请求自定义声明,只需将声明名称作为键传递到ID4meClient.get_consent_url
方法的userinfo_claims
或id_token_claims
参数中即可。
示例
...
link = client.get_consent_url(
ctx=context,
claimsrequest=ID4meClaimsRequest(
userinfo_claims={
OIDCClaim.email: ID4meClaimRequestProperties(essential=True, reason='Test other confusing reason'),
'id4me.custom': ID4meClaimRequestProperties(essential=True, reason='Custom claim reason')
})
)
...
变更日志
版本 | 日期 | 更改 |
---|---|---|
0.0.24 | 2019-11-26 | 新增功能:支持"id_token"的"alg"为"none" 新增功能:允许覆盖权威查找 新增功能:"userinfo_signing_required"现在可以在客户端代码中配置 新增功能:添加了RS384和RS512作为支持的签名选项 重构:清理了动态客户端注册的代码 错误修复:仅在支持的情况下使用'none'算法 |
0.0.23 | 2019-10-04 | 新增功能:添加了对plain JSON用户信息的支持 新功能:当身份提供者(IdP)不支持时,使用作用域参数代替声明 新增:包含示例代码 |
0.0.22 | 2019-07-29 | 错误修复:id4me_rp_client.helper 没有导出到发布库 |
0.0.21 | 2019-07-29 | 错误修复:未正确处理 YXDOMAIN 的情况 错误修复:避免尝试解析空域名 错误修复:增加了对空状态更好的处理 日志记录:添加所有异常的日志记录(调试级别) |
0.0.20 | 2019-05-23 | 新功能:根据在 https://gitlab.com/ID4me/documentation/merge_requests/7 提出的规范变更进行电子邮件地址哈希处理 小修改:最终弃用了注册中的 preferred_client_id 新功能:通过 NetworkConfig 可配置超时时间 |
0.0.19 | 2019-03-24 | 测试:将 Kopano 添加到集成测试 错误修复:重新注册的宽限期设置为 5 分钟而不是 2 小时 测试:为 mojeid 测试账户添加密码 |
0.0.18 | 2019-03-23 | 新功能:添加了对电子邮件-like 标识符的支持(只需将 @ 替换为 .) 新功能:使用作用域请求声明 解决方案:接受 token_type 为 'Bearer' 和 'bearer' 错误修复:正确分配了 'tos_uri' |
0.0.17 | 2019-03-19 | 安全修复:限制下载数据的超时时间和大小(防止 DDoS 攻击) 安全修复:限制分布式声明的递归级别(防止 DDoS 攻击) |
0.0.16 | 2019-03-11 | 重大更改:移除了与旧 _openid 记录格式的向后兼容性 |
0.0.15 | 2019-02-27 | - 新功能:自动重新注册过期的客户端注册 - 明确的参数以启用/阻止自动客户端注册 |
0.0.14 | 2019-02-25 | 无功能更改。README 中的示例代码已修复 |
0.0.13 | 2019-02-25 | 无功能更改。添加了自定义声明的测试和示例 |
0.0.12 | 2019-02-21 | 错误修复:当未使用加密但缺少私钥时抛出异常 |
0.0.11 | 2019-02-21 | 错误修复:序列化 ID4meContext 时出错 |
0.0.10 | 2019-02-18 | API 破坏性更改:将客户端配置加载回调移动到客户端对象中,以从 ID4meContext 中移除秘密数据,这在某些框架中可能通过 cookie 发送 |
项目详情
关闭
id4me-rp-client-0.0.24.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 93aaafba6be20d627cc434d64f3ce22338af77b582f61e2de10bf1cdb1f1cd97 |
|
MD5 | a4f5a40e7ca30e5c3702dbd6eeea1af9 |
|
BLAKE2b-256 | 373b40440c49c3ddde2a8317f0c0df47944afc1ad5d6da8cc01b374120d573d2 |