-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_server_00a_client_configure.py
More file actions
139 lines (124 loc) · 5.15 KB
/
test_server_00a_client_configure.py
File metadata and controls
139 lines (124 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import json
import os
from idpyoidc.server import OPConfiguration
from idpyoidc.server import Server
from idpyoidc.server.client_configure import verify_oidc_client_information
from idpyoidc.util import load_config_file
from tests import full_path
BASEDIR = os.path.abspath(os.path.dirname(__file__))
EXTRA = {
"token_usage_rules": {
"authorization_code": {
"expires_in": 600,
"supports_minting": ["access_token", "refresh_token"],
},
"refresh_token": {"supports_minting": ["access_token"]},
},
"revoke_refresh_on_issue": True,
"token_exchange": {
"urn:ietf:params:oauth:grant-type:token-exchange": {
"class": "idpyoidc.server.oidc.token.TokenExchangeHelper",
"kwargs": {
"subject_token_types_supported": [
"urn:ietf:params:oauth:token-type:access_token",
"urn:ietf:params:oauth:token-type:refresh_token",
"urn:ietf:params:oauth:token-type:id_token",
],
"requested_token_types_supported": [
"urn:ietf:params:oauth:token-type:access_token",
"urn:ietf:params:oauth:token-type:refresh_token",
"urn:ietf:params:oauth:token-type:id_token",
],
"policy": {
"urn:ietf:params:oauth:token-type:access_token": {
"function": "/path/to/function",
"kwargs": {"audience": ["https://example.com"], "scopes": ["openid"]},
},
"urn:ietf:params:oauth:token-type:refresh_token": {
"function": "/path/to/function",
"kwargs": {"resource": ["https://example.com"], "scopes": ["openid"]},
},
"": {"function": "/path/to/function", "kwargs": {"scopes": ["openid"]}},
},
},
},
"allowed_scopes": ["scope"],
"scopes_to_claims": {"scope_a": ["claim1", "claim2"], "scope_b": []},
"add_claims": {
"always": {
"userinfo": ["email", "phone"],
# Always add "email" and "phone" in the userinfo response if such claims exists
"id_token": {"email": None},
# Always add "email" in the id_token if such a claim exists
"introspection": {"email": {"value": "a@a.com"}},
# Add "email" in the introspection response only if its value is "a@a.com"
},
"by_scope": {
"id_token": False,
},
},
},
}
def test_op_configure_oidc_clients_simple():
_str = open(full_path(full_path("op_config.json"))).read()
_conf = json.loads(_str)
_conf["oidc_clients"] = {
"client1": {
"client_id": "client1",
"client_secret": "Namnam",
"redirect_uris": ["https://openidconnect.net/callback", ""],
"response_types": ["code"],
},
"client2": {
"client_id": "client2",
"client_secret": "spraket",
"redirect_uris": ["https://app1.example.net/foo", "https://app2.example.net/bar"],
"response_types": ["code"],
},
"client3": {
"client_id": "client3",
"client_secret": "2222222222222222222222222222222222222222",
"redirect_uris": ["https://127.0.0.1:8090/authz_cb/bobcat"],
"post_logout_redirect_uri": "https://openidconnect.net/",
"response_types": ["code"],
},
}
op_conf = OPConfiguration(conf=_conf, base_path=BASEDIR)
assert op_conf
def test_verify_oidc_client_information_complext():
_conf = load_config_file(full_path("op_config.json"))
server = Server(OPConfiguration(conf=_conf, base_path=BASEDIR))
client_conf = {
"client1": {
"client_id": "client1",
"client_secret": "Namnam",
"redirect_uris": ["https://openidconnect.net/callback", ""],
"response_types": ["code"],
}
}
client_conf["client1"].update(EXTRA)
res = verify_oidc_client_information(client_conf, upstream_get=server.upstream_get)
assert res
for cli, _cli_conf in res.items():
print(_cli_conf.extra())
def test_verify_oidc_client_information_2():
_conf = load_config_file(full_path("op_config.json"))
server = Server(OPConfiguration(conf=_conf, base_path=BASEDIR), cwd=full_path(""))
client_conf = {
"client1": {
"client_id": "client1",
"client_secret": "Namnam",
"redirect_uris": ["https://openidconnect.net/callback", ""],
"response_types": ["code"],
"token_usage_rules": {
"authorization_code": {
"expires_in": 600,
"supports_minting": ["access_token", "refresh_token"],
},
"refresh_token": {"supports_minting": ["access_token"]},
"dummy_token": {"supports_minting": ["foobar_token"]},
},
}
}
res = verify_oidc_client_information(client_conf, upstream_get=server.upstream_get)
assert res