Skip to content

Commit

Permalink
Wrappers for a number of CryptoJWT methods to make sure there is only…
Browse files Browse the repository at this point in the history
… one copy of a key in the key jar (idpyoidc.key_import).

Changed the name of a module from metadata to alg_info since metadata was a very bad name.
Removed defaults for request_uri_parameter_supported and request_parameter_supported.
Moved the transform module from claims to idpyoidc.
Bumped the version to 5.0.0
  • Loading branch information
rohe committed Nov 25, 2024
1 parent 2335ecd commit 60028ea
Show file tree
Hide file tree
Showing 39 changed files with 600 additions and 704 deletions.
2 changes: 1 addition & 1 deletion demo/oauth2_add_on_dpop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from common import KEYDEFS
from common import full_path
from flow import Flow
from idpyoidc.metadata import get_signing_algs
from idpyoidc.alg_info import get_signing_algs
from idpyoidc.client.oauth2 import Client
from idpyoidc.server import Server
from idpyoidc.server.configure import ASConfiguration
Expand Down
127 changes: 0 additions & 127 deletions private/xmetadata/oidc.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/idpyoidc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = "Roland Hedberg"
__version__ = "4.3.0"
__version__ = "5.0.0"

VERIFIED_CLAIM_PREFIX = "__verified"

Expand All @@ -10,7 +10,7 @@ def verified_claim_name(claim):

def proper_path(path):
"""
Clean up the path specification so it looks like something I could use.
Clean up the path specification such that it looks like something I could use.
"./" <path> "/"
"""
if path.startswith("./"):
Expand Down
67 changes: 67 additions & 0 deletions src/idpyoidc/alg_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from functools import cmp_to_key
import logging

from cryptojwt.jwe import DEPRECATED
from cryptojwt.jwe import SUPPORTED
from cryptojwt.jws.jws import SIGNER_ALGS

logger = logging.getLogger(__name__)

SIGNING_ALGORITHM_SORT_ORDER = ["RS", "ES", "PS", "HS", "Ed"]


def cmp(a, b):
return (a > b) - (a < b)


def alg_cmp(a, b):
if a == "none":
return 1
elif b == "none":
return -1

_pos1 = SIGNING_ALGORITHM_SORT_ORDER.index(a[0:2])
_pos2 = SIGNING_ALGORITHM_SORT_ORDER.index(b[0:2])
if _pos1 == _pos2:
return (a > b) - (a < b)
elif _pos1 > _pos2:
return 1
else:
return -1


def get_signing_algs():
# Assumes Cryptojwt
_algs = [name for name in list(SIGNER_ALGS.keys()) if name != "none" and name not in DEPRECATED["alg"]]
return sorted(_algs, key=cmp_to_key(alg_cmp))


def get_encryption_algs():
return SUPPORTED["alg"]


def get_encryption_encs():
return SUPPORTED["enc"]


def array_or_singleton(claim_spec, values):
if isinstance(claim_spec[0], list):
if isinstance(values, list):
return values
else:
return [values]
else:
if isinstance(values, list):
return values[0]
else: # singleton
return values


def is_subset(a, b):
if isinstance(a, list):
if isinstance(b, list):
return set(b).issubset(set(a))
elif isinstance(b, list):
return a in b
else:
return a == b
Loading

0 comments on commit 60028ea

Please sign in to comment.