Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit afa043e

Browse files
authored
Merge pull request #105 from IdentityPython/init_cdb
Allowing specification of a client DB in the configuration file.
2 parents a2b1353 + 6efdb5e commit afa043e

7 files changed

Lines changed: 64 additions & 17 deletions

File tree

docs/source/contents/conf.rst

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,32 @@ An example::
156156
backchannel_logout_session_supported: True
157157
check_session_iframe: https://127.0.0.1:5000/check_session_iframe
158158

159-
-------------
159+
---------
160+
client_db
161+
---------
162+
163+
If you're running an OP with static client registration you want to keep the
164+
registered clients in a database separate from the session database since
165+
it will change independent of the OP process. In this case you need this.
166+
If you are on the other hand only allowing dynamic client registration then
167+
keeping registered clients in the session database makes total sense.
168+
169+
The class you reference in the specification MUST be a subclass of
170+
oidcmsg.storage.DictType and have some of the methods a dictionary has.
171+
172+
An example::
173+
174+
client_db: {
175+
"class": 'oidcmsg.abfile.AbstractFileSystem',
176+
"kwargs": {
177+
'fdir': full_path("afs"),
178+
'value_conv': 'oidcmsg.util.JSON'
179+
}
180+
}
181+
182+
--------------
160183
cookie_handler
161-
-------------
184+
--------------
162185

163186
An example::
164187

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[metadata]
99
name = "oidcop"
10-
version = "2.0.0"
10+
version = "2.1.0"
1111
author = "Roland Hedberg"
1212
author_email = "roland@catalogix.se"
1313
description = "Python implementation of an OAuth2 AS and an OIDC Provider"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def run_tests(self):
7272
"Programming Language :: Python :: 3.9",
7373
"Topic :: Software Development :: Libraries :: Python Modules"],
7474
install_requires=[
75-
"oidcmsg==1.3.3-1",
75+
"oidcmsg==1.4.0",
7676
"cryptojwt==1.5.2",
7777
"pyyaml",
7878
"jinja2>=2.11.3",

src/oidcop/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import secrets
22

3-
__version__ = "2.0.1"
3+
__version__ = "2.1.0"
44

55
DEF_SIGN_ALG = {
66
"id_token": "RS256",

src/oidcop/configure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class EntityConfiguration(Base):
192192
"base_url": "",
193193
"capabilities": None,
194194
"claims_interface": None,
195+
"client_db": None,
195196
"cookie_handler": None,
196197
"endpoint": {},
197198
"httpc_params": {},

src/oidcop/endpoint_context.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class EndpointContext(OidcContext):
9393
"args": {},
9494
# "authn_broker": AuthnBroker,
9595
# "authz": AuthzHandling,
96-
"cdb": {},
96+
"cdb": "DICT_TYPE",
9797
"conf": {},
9898
# "cookie_handler": None,
9999
"cwd": "",
@@ -129,8 +129,15 @@ def __init__(
129129
OidcContext.__init__(self, conf, keyjar, entity_id=conf.get("issuer", ""))
130130
self.conf = conf
131131

132+
_client_db = conf.get("client_db")
133+
if _client_db:
134+
logger.debug(f"Loading client db using: {_client_db}")
135+
self.cdb = importer(_client_db["class"])(**_client_db["kwargs"])
136+
else:
137+
logger.debug("No special client db, will use memory based dictionary")
138+
self.cdb = {}
139+
132140
# For my Dev environment
133-
self.cdb = {}
134141
self.jti_db = {}
135142
self.registration_access_token = {}
136143
# self.session_db = {}

tests/test_00_server.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
from copy import copy
2+
from copy import deepcopy
13
import io
24
import json
35
import os
4-
from copy import copy
56

6-
import yaml
77
from cryptojwt.key_jar import build_keyjar
8+
from oidcmsg.storage.abfile import AbstractFileSystem
9+
import yaml
810

9-
import oidcop.login_hint
1011
from oidcop.configure import OPConfiguration
12+
import oidcop.login_hint
1113
from oidcop.oidc.add_on.pkce import add_pkce_support
1214
from oidcop.oidc.authorization import Authorization
1315
from oidcop.oidc.provider_config import ProviderConfiguration
@@ -32,7 +34,7 @@ def full_path(local_file):
3234

3335
KEYJAR = build_keyjar(KEYDEFS)
3436

35-
conf = {
37+
CONF = {
3638
"issuer": "https://example.com/",
3739
"password": "mycket hemligt",
3840
"verify_ssl": False,
@@ -44,8 +46,8 @@ def full_path(local_file):
4446
"class": ProviderConfiguration,
4547
"kwargs": {},
4648
},
47-
"registration_endpoint": {"path": "registration", "class": Registration, "kwargs": {},},
48-
"authorization_endpoint": {"path": "authorization", "class": Authorization, "kwargs": {},},
49+
"registration_endpoint": {"path": "registration", "class": Registration, "kwargs": {}, },
50+
"authorization_endpoint": {"path": "authorization", "class": Authorization, "kwargs": {}, },
4951
"token_endpoint": {"path": "token", "class": Token, "kwargs": {}},
5052
"userinfo_endpoint": {
5153
"path": "userinfo",
@@ -114,14 +116,14 @@ def test_capabilities_default():
114116

115117

116118
def test_capabilities_subset1():
117-
_cnf = copy(conf)
119+
_cnf = deepcopy(CONF)
118120
_cnf["capabilities"] = {"response_types_supported": ["code"]}
119121
server = Server(_cnf)
120122
assert server.endpoint_context.provider_info["response_types_supported"] == ["code"]
121123

122124

123125
def test_capabilities_subset2():
124-
_cnf = copy(conf)
126+
_cnf = deepcopy(CONF)
125127
_cnf["capabilities"] = {"response_types_supported": ["code", "id_token"]}
126128
server = Server(_cnf)
127129
assert set(server.endpoint_context.provider_info["response_types_supported"]) == {
@@ -131,15 +133,29 @@ def test_capabilities_subset2():
131133

132134

133135
def test_capabilities_bool():
134-
_cnf = copy(conf)
136+
_cnf = deepcopy(CONF)
135137
_cnf["capabilities"] = {"request_uri_parameter_supported": False}
136138
server = Server(_cnf)
137139
assert server.endpoint_context.provider_info["request_uri_parameter_supported"] is False
138140

139141

140142
def test_cdb():
141-
server = Server(conf)
143+
_cnf = deepcopy(CONF)
144+
server = Server(_cnf)
142145
_clients = yaml.safe_load(io.StringIO(client_yaml))
143146
server.endpoint_context.cdb = _clients["oidc_clients"]
144147

145148
assert set(server.endpoint_context.cdb.keys()) == {"client1", "client2", "client3"}
149+
150+
151+
def test_cdb_afs():
152+
_cnf = copy(CONF)
153+
_cnf["client_db"] = {
154+
"class": 'oidcmsg.storage.abfile.AbstractFileSystem',
155+
"kwargs": {
156+
'fdir': full_path("afs"),
157+
'value_conv': 'oidcmsg.util.JSON'
158+
}
159+
}
160+
server = Server(_cnf)
161+
assert isinstance(server.endpoint_context.cdb, AbstractFileSystem)

0 commit comments

Comments
 (0)