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

Commit 1753843

Browse files
committed
Redesigned configuration handling.
1 parent cfd79b3 commit 1753843

6 files changed

Lines changed: 181 additions & 152 deletions

File tree

example/flask_rp/application.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from cryptojwt.key_jar import init_key_jar
66
from flask.app import Flask
77

8-
from oidcrp.configure import Configuration
98
from oidcrp.rp_handler import RPHandler
109

1110
dir_path = os.path.dirname(os.path.realpath(__file__))
@@ -14,9 +13,9 @@
1413
def init_oidc_rp_handler(app):
1514
_rp_conf = app.rp_config
1615

17-
if _rp_conf.rp_keys:
18-
_kj = init_key_jar(**_rp_conf.rp_keys)
19-
_path = _rp_conf.rp_keys['public_path']
16+
if _rp_conf.keys:
17+
_kj = init_key_jar(**_rp_conf.keys)
18+
_path = _rp_conf.keys['public_path']
2019
# removes ./ and / from the begin of the string
2120
_path = re.sub('^(.)/', '', _path)
2221
else:
@@ -31,11 +30,11 @@ def init_oidc_rp_handler(app):
3130
return rph
3231

3332

34-
def oidc_provider_init_app(config_file, name=None, **kwargs):
33+
def oidc_provider_init_app(config, name=None, **kwargs):
3534
name = name or __name__
3635
app = Flask(name, static_url_path='', **kwargs)
3736

38-
app.rp_config = Configuration.create_from_config_file(config_file)
37+
app.rp_config = config
3938

4039
# Session key for the application session
4140
app.config['SECRET_KEY'] = os.urandom(12).hex()

example/flask_rp/conf.json

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,6 @@
3838
"httpc_params": {
3939
"verify": false
4040
},
41-
"keydefs": [
42-
{
43-
"type": "RSA",
44-
"key": "",
45-
"use": [
46-
"sig"
47-
]
48-
},
49-
{
50-
"type": "EC",
51-
"crv": "P-256",
52-
"use": [
53-
"sig"
54-
]
55-
}
56-
],
5741
"rp_keys": {
5842
"private_path": "private/jwks.json",
5943
"key_defs": [
@@ -75,27 +59,6 @@
7559
"public_path": "static/jwks.json",
7660
"read_only": false
7761
},
78-
"client_preferences": {
79-
"application_name": "rphandler",
80-
"application_type": "web",
81-
"contacts": [
82-
"ops@example.com"
83-
],
84-
"response_types": [
85-
"code"
86-
],
87-
"scope": [
88-
"openid",
89-
"profile",
90-
"email",
91-
"address",
92-
"phone"
93-
],
94-
"token_endpoint_auth_method": [
95-
"client_secret_basic",
96-
"client_secret_post"
97-
]
98-
},
9962
"services": {
10063
"discovery": {
10164
"class": "oidcrp.oidc.provider_info_discovery.ProviderInfoDiscovery",

example/flask_rp/wsgi.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,33 @@
11
#!/usr/bin/env python3
22

3-
import logging
43
import os
54
import sys
65

6+
from oidcrp.configure import Configuration
7+
from oidcrp.configure import RPConfiguration
8+
from oidcrp.configure import create_from_config_file
79
from oidcrp.util import create_context
810

911
try:
1012
from . import application
1113
except ImportError:
1214
import application
1315

14-
# logger = logging.getLogger("")
15-
# RP_LOGFILE_NAME = os.environ.get('RP_LOGFILE_NAME', 'flrp.log')
16-
#
17-
# hdlr = logging.FileHandler(RP_LOGFILE_NAME)
18-
# log_format = ("%(asctime)s %(name)s:%(levelname)s "
19-
# "%(message)s [%(name)s.%(funcName)s:%(lineno)s]")
20-
# base_formatter = logging.Formatter(log_format)
21-
#
22-
# hdlr.setFormatter(base_formatter)
23-
# logger.addHandler(hdlr)
24-
# logger.setLevel(logging.DEBUG)
25-
#
26-
# stdout = logging.StreamHandler()
27-
# stdout.setFormatter(base_formatter)
28-
# logger.addHandler(stdout)
29-
3016
dir_path = os.path.dirname(os.path.realpath(__file__))
3117

3218
if __name__ == "__main__":
3319
conf = sys.argv[1]
3420
name = 'oidc_rp'
3521
template_dir = os.path.join(dir_path, 'templates')
36-
app = application.oidc_provider_init_app(conf, name,
37-
template_folder=template_dir)
38-
_web_conf = app.rp_config.web_conf
22+
23+
_config = create_from_config_file(Configuration,
24+
entity_conf_class=RPConfiguration,
25+
filename=conf)
26+
27+
app = application.oidc_provider_init_app(_config.rp, name, template_folder=template_dir)
28+
_web_conf = _config.web_conf
3929
context = create_context(dir_path, _web_conf)
4030

4131
debug = _web_conf.get('debug', True)
42-
app.run(host=app.rp_config.domain, port=app.rp_config.port,
32+
app.run(host=_web_conf["domain"], port=_web_conf["port"],
4333
debug=_web_conf.get("debug", False), ssl_context=context)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def run_tests(self):
7373
],
7474
tests_require=[
7575
'pytest',
76-
'pytest-localserver',
76+
'pytest-localserver'
7777
],
7878
zip_safe=False,
7979
cmdclass={'test': PyTest},

0 commit comments

Comments
 (0)