Skip to content

Commit

Permalink
Merge pull request #2 from IdentityPython/develop
Browse files Browse the repository at this point in the history
Cleaning up after refactoring. Adjustments to Configure.
  • Loading branch information
rohe authored Mar 30, 2022
2 parents 17443dc + 804af5b commit 2d26564
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- '3.7'
- '3.8'
- '3.9'
- '3.10'

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

Implementation of everything OIDC and OAuth2.

idpyoidc is the 2nd layer in the
JwtConnect stack (cryptojwt, idpyoidc)
idpyoidc is the 2nd layer in the JwtConnect stack (cryptojwt, idpyoidc)

Please read the [Official Documentation](https://idpyoidc.readthedocs.io/) for getting usage examples and further informations.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[metadata]
name = "idpyoidc"
version = "1.0.0"
version = "1.0.1"
author = "Roland Hedberg"
author_email = "[email protected]"
description = "Everything OAuth2 and OIDC"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run_tests(self):
setup(
name="idpyoidc",
version=version,
description="Python implementation of OAuth2 and OpenID Connect messages",
description="Python implementation of everything OAuth2 and OpenID Connect",
long_description=README,
long_description_content_type='text/markdown',
author="Roland Hedberg",
Expand Down
2 changes: 1 addition & 1 deletion src/idpyoidc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = "Roland Hedberg"
__version__ = "1.0.0"
__version__ = "1.0.1"

import os
from typing import Dict
Expand Down
32 changes: 28 additions & 4 deletions src/idpyoidc/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Dict
from typing import List
from typing import Optional
from typing import Union

from idpyoidc.logging import configure_logging
from idpyoidc.util import load_config_file
Expand Down Expand Up @@ -38,6 +39,9 @@ def add_path_to_directory_name(directory_name, base_path):

def add_base_path(conf: dict, base_path: str, attributes: List[str], attribute_type: str = "file"):
for key, val in conf.items():
if not val:
continue

if key in attributes:
if attribute_type == "file":
conf[key] = add_path_to_filename(val, base_path)
Expand Down Expand Up @@ -168,7 +172,7 @@ def complete_paths(self, conf: Dict, keys: List[str], default_config: Dict, base

def format(self, conf, base_path: str, domain: str, port: int,
file_attributes: Optional[List[str]] = None,
dir_attributes: Optional[List[str]] = None) -> None:
dir_attributes: Optional[List[str]] = None) -> Union[Dict, str]:
"""
Formats parts of the configuration. That includes replacing the strings {domain} and {port}
with the used domain and port and making references to files and directories absolute
Expand All @@ -183,11 +187,17 @@ def format(self, conf, base_path: str, domain: str, port: int,
"""
if isinstance(conf, dict):
if file_attributes:
add_base_path(conf, base_path, file_attributes, attribute_type="file")
conf = add_base_path(conf, base_path, file_attributes, attribute_type="file")
if dir_attributes:
add_base_path(conf, base_path, dir_attributes, attribute_type="dir")
conf = add_base_path(conf, base_path, dir_attributes, attribute_type="dir")
if isinstance(conf, dict):
set_domain_and_port(conf, domain=domain, port=port)
conf = set_domain_and_port(conf, domain=domain, port=port)
elif isinstance(conf, list):
conf = [_conv(v, domain=domain, port=port) for v in conf]
elif isinstance(conf, str):
conf = _conv(conf, domain, port)

return conf


class Configuration(Base):
Expand Down Expand Up @@ -215,10 +225,24 @@ def __init__(self,
self.web_conf = lower_or_upper(self.conf, "webserver")

if entity_conf:
skip = [ec["path"] for ec in entity_conf if 'path' in ec]
check = [l[0] for l in skip]

self.extend(conf=self.conf, base_path=base_path,
domain=self.domain, port=self.port, entity_conf=entity_conf,
file_attributes=self._file_attributes,
dir_attributes=self._dir_attributes)
for key, val in conf.items():
if key in ["logging", "webserver", "domain", "port"]:
continue

if key in check:
continue

setattr(self, key, val)
else:
for key, val in conf.items():
setattr(self, key, val)


def create_from_config_file(cls,
Expand Down
22 changes: 14 additions & 8 deletions src/idpyoidc/server/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class EntityConfiguration(Base):
"endpoint": {},
"httpc_params": {},
"issuer": "",
"keys": None,
"key_conf": None,
"session_params": None,
"template_dir": None,
"token_handler_args": {},
Expand All @@ -168,17 +168,17 @@ def __init__(
):

conf = copy.deepcopy(conf)
Base.__init__(self, conf, base_path, file_attributes, dir_attributes=dir_attributes)
Base.__init__(self, conf, base_path, file_attributes=file_attributes,
dir_attributes=dir_attributes, domain=domain, port=port)

self.key_conf = conf.get('key_conf')
self.key_conf = conf.get('key_conf', conf.get('keys'))

for key in self.parameter.keys():
_val = conf.get(key)
if not _val:
if key in self.default_config:
_val = copy.deepcopy(self.default_config[key])
self.format(
_val,
_val = self.format(
copy.deepcopy(self.default_config[key]),
base_path=base_path,
file_attributes=file_attributes,
domain=domain,
Expand All @@ -189,7 +189,7 @@ def __init__(
continue

if key not in DEFAULT_EXTENDED_CONF:
logger.warning(f"{key} not seems to be a valid configuration parameter")
logger.warning(f"{key} does not seems to be a valid configuration parameter")
elif not _val:
logger.warning(f"{key} not configured, using default configuration values")

Expand Down Expand Up @@ -334,6 +334,10 @@ def __init__(
"refresh_token",
],
},
"claims_interface": {
"class": "idpyoidc.server.session.claims.ClaimsInterface",
"kwargs": {}
},
"cookie_handler": {
"class": "idpyoidc.server.cookie_handler.CookieHandler",
"kwargs": {
Expand Down Expand Up @@ -462,7 +466,9 @@ def __init__(
"jwks_def": {
"private_path": "private/token_jwks.json",
"read_only": False,
"key_defs": [{"type": "oct", "bytes": "24", "use": ["enc"], "kid": "code"}],
"key_defs": [
{"type": "oct", "bytes": "24", "use": ["enc"], "kid": "code"}
],
},
"code": {"kwargs": {"lifetime": 600}},
"token": {
Expand Down
11 changes: 8 additions & 3 deletions tests/test_server_00_configure.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import json
import os

import pytest

from idpyoidc.configure import Configuration
from idpyoidc.configure import create_from_config_file
from idpyoidc.logging import configure_logging
from idpyoidc.server.configure import OPConfiguration
import pytest

BASEDIR = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -99,7 +98,13 @@ def test_op_configure_default_from_file():
def test_server_configure():
configuration = create_from_config_file(
Configuration,
entity_conf=[{"class": OPConfiguration, "attr": "op", "path": ["op", "server_info"]}],
entity_conf=[
{
"class": OPConfiguration,
"attr": "op",
"path": ["op", "server_info"]
}
],
filename=full_path("srv_config.json"),
base_path=BASEDIR,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_server_20a_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_capabilities_default():
"code id_token token",
}
assert server.endpoint_context.provider_info["request_uri_parameter_supported"] is True
assert server.endpoint_context.jwks_uri == 'https://127.0.0.1:80/static/jwks.json'
assert server.endpoint_context.jwks_uri == 'https://127.0.0.1:443/static/jwks.json'


def test_capabilities_subset1():
Expand Down

0 comments on commit 2d26564

Please sign in to comment.