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

Commit 0fd9ed0

Browse files
committed
Configuration class.
configuration modified to use the new format.
1 parent 1a48e02 commit 0fd9ed0

2 files changed

Lines changed: 45 additions & 65 deletions

File tree

flask_rp/application.py

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,28 @@
66
from flask.app import Flask
77

88
from oidcrp import RPHandler
9-
from oidcrp.util import load_yaml_config
9+
from oidcrp.configure import Configuration
1010

1111
dir_path = os.path.dirname(os.path.realpath(__file__))
1212

1313

1414
def init_oidc_rp_handler(app):
15-
verify_ssl = app.config.get('VERIFY_SSL')
16-
httpc_params = {"verify": verify_ssl}
17-
18-
_cert = app.config.get("CLIENT_CERT")
19-
_key = app.config.get("CLIENT_KEY")
20-
if _cert and _key:
21-
httpc_params["cert"] = (_cert, _key)
22-
elif _cert:
23-
httpc_params["cert"] = _cert
24-
25-
hash_seed = app.config.get('HASH_SEED')
26-
if not hash_seed:
27-
hash_seed = "BabyHoldOn"
28-
29-
rp_keys_conf = app.config.get('RP_KEYS')
30-
if rp_keys_conf is None:
31-
rp_keys_conf = app.config.get('OIDC_KEYS')
32-
33-
if rp_keys_conf:
34-
_kj = init_key_jar(**rp_keys_conf)
35-
_path = rp_keys_conf['public_path']
15+
_rp_conf = app.rp_config
16+
17+
if _rp_conf.rp_keys:
18+
_kj = init_key_jar(**_rp_conf.rp_keys)
19+
_path = _rp_conf.rp_keys['public_path']
3620
# removes ./ and / from the begin of the string
3721
_path = re.sub('^(.)/', '', _path)
3822
else:
3923
_kj = KeyJar()
4024
_path = ''
41-
_kj.httpc_params = httpc_params
25+
_kj.httpc_params = _rp_conf.httpc_params
4226

43-
rph = RPHandler(base_url=app.config.get('BASEURL'),
44-
hash_seed=hash_seed, keyjar=_kj, jwks_path=_path,
45-
client_configs=app.config.get('CLIENTS'),
46-
services=app.config.get('SERVICES'), httpc_params=httpc_params)
27+
rph = RPHandler(base_url=_rp_conf.base_url,
28+
hash_seed=_rp_conf.hash_seed, keyjar=_kj, jwks_path=_path,
29+
client_configs=_rp_conf.clients,
30+
services=_rp_conf.services, httpc_params=_rp_conf.httpc_params)
4731

4832
return rph
4933

@@ -52,14 +36,8 @@ def oidc_provider_init_app(config_file, name=None, **kwargs):
5236
name = name or __name__
5337
app = Flask(name, static_url_path='', **kwargs)
5438

55-
if config_file.endswith('.yaml'):
56-
app.config.update(load_yaml_config(config_file))
57-
elif config_file.endswith('.py'):
58-
app.config.from_pyfile(os.path.join(dir_path, config_file))
59-
else:
60-
raise ValueError('Unknown configuration format')
61-
62-
app.config['SECRET_KEY'] = os.urandom(12).hex()
39+
app.rp_config = Configuration.create_from_config_file(config_file)
40+
# app.config['SECRET_KEY'] = os.urandom(12).hex()
6341

6442
app.users = {'test_user': {'name': 'Testing Name'}}
6543

flask_rp/conf.yaml

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
PORT: 8090
2-
BASEURL: "https://127.0.0.1:8090"
1+
port: &port 8090
2+
domain: &domain 127.0.0.1
3+
base_url: "https://{domain}:{port}"
34

4-
# If BASE is https these has to be specified
5-
SERVER_CERT: "certs/cert.pem"
6-
SERVER_KEY: "certs/key.pem"
7-
CA_BUNDLE: ''
8-
# If you want the clients cert to be verified
9-
#VERIFY_USER: optional
5+
http_params:
6+
# This is just for testing an local usage. In all other cases it MUST be True
7+
verify_ssl: false
8+
# Client side
9+
#client_cert: "certs/client.crt"
10+
#client_key: "certs/client.key"
1011

11-
# This is just for testing an local usage. In all other cases it MUST be True
12-
VERIFY_SSL: false
13-
14-
# Client side
15-
#CLIENT_CERT: "certs/client.crt"
16-
#CLIENT_KEY: "certs/client.key"
17-
18-
KEYDEFS: &keydef
12+
keydefs: &keydef
1913
-
2014
"type": "RSA"
2115
"key": ''
@@ -25,27 +19,27 @@ KEYDEFS: &keydef
2519
"crv": "P-256"
2620
"use": ["sig"]
2721

28-
HTML_HOME: 'html'
29-
SECRET_KEY: 'secret_key'
30-
SESSION_COOKIE_NAME: 'rp_session'
31-
PREFERRED_URL_SCHEME: 'https'
22+
html_home: 'html'
23+
secret_key: 'secret_key'
24+
session_cookie_name: 'rp_session'
25+
preferred_url_scheme: 'https'
3226

33-
RP_KEYS:
34-
'private_path': './private/jwks.json'
27+
rp_keys:
28+
'private_path': 'private/jwks.json'
3529
'key_defs': *keydef
36-
'public_path': './static/jwks.json'
30+
'public_path': 'static/jwks.json'
3731
# this will create the jwks files if they are absent
3832
'read_only': False
3933

40-
CLIENT_PREFERENCES: &id001
34+
client_preferences: &id001
4135
application_name: rphandler
4236
application_type: web
4337
contacts: [ops@example.com]
4438
response_types: [code]
4539
scope: [openid, profile, email, address, phone]
4640
token_endpoint_auth_method: [client_secret_basic, client_secret_post]
4741

48-
SERVICES: &id002
42+
services: &id002
4943
discovery:
5044
class: oidcservice.oidc.provider_info_discovery.ProviderInfoDiscovery
5145
kwargs: {}
@@ -68,16 +62,16 @@ SERVICES: &id002
6862
class: oidcservice.oidc.end_session.EndSession
6963
kwargs: {}
7064

71-
CLIENTS:
65+
clients:
7266
"":
7367
client_preferences: *id001
7468
redirect_uris: None
7569
services: *id002
7670
flop:
7771
client_preferences: *id001
7872
issuer: https://127.0.0.1:5000/
79-
jwks_uri: https://127.0.0.1:8090/static/jwks.json
80-
redirect_uris: ['https://127.0.0.1:8090/authz_cb/flop']
73+
jwks_uri: 'static/jwks.json'
74+
redirect_uris: ['authz_cb/flop']
8175
services: *id002
8276
add_ons:
8377
pkce:
@@ -87,5 +81,13 @@ CLIENTS:
8781
code_challenge_method: S256
8882

8983

90-
# Whether an attempt to fetch the userinfo should be made
91-
USERINFO: true
84+
webserver:
85+
port: *port
86+
domain: *domain
87+
# If BASE is https these has to be specified
88+
server_cert: "certs/cert.pem"
89+
server_key: "certs/key.pem"
90+
# If you want the clients cert to be verified
91+
# verify_user: optional
92+
# The you also need
93+
# ca_bundle: ''

0 commit comments

Comments
 (0)