Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Use per client usage rules #110

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/oidcendpoint/authz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def usage_rules(self, client_id):
else:
_usage_rules = {}

if not client_id:
return _usage_rules

try:
_per_client = self.endpoint_context.cdb[client_id]["token_usage_rules"]
except KeyError:
Expand All @@ -52,8 +55,12 @@ def usage_rules_for(self, client_id, token_type):
except KeyError:
return {}

def __call__(self, session_id: str, request: Union[dict, Message],
resources: Optional[list] = None) -> Grant:
def __call__(
self,
session_id: str,
request: Union[dict, Message],
resources: Optional[list] = None,
) -> Grant:
args = self.grant_config.copy()

scope = request.get("scope")
Expand All @@ -74,6 +81,8 @@ def __call__(self, session_id: str, request: Union[dict, Message],
for key, val in args.items():
if key == "expires_in":
grant.set_expires_at(val)
if key == "usage_rules":
setattr(grant, key, self.usage_rules(request.get("client_id")))
else:
setattr(grant, key, val)

Expand Down