Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
edulix committed Nov 12, 2023
1 parent 4979c6c commit c57a25d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
6 changes: 5 additions & 1 deletion iam/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ def restrict_extra_fields(fields):
]

def restrict_alt_auth_methods():
from authmethods import patch_auth_event
if self.alternative_auth_methods is None:
return self.alternative_auth_methods

Expand All @@ -675,7 +676,10 @@ def restrict_alt_auth_methods():
),
public_name=alt_auth_method["public_name"],
public_name_i18n=alt_auth_method["public_name_i18n"],
icon=alt_auth_method["icon"]
icon=alt_auth_method["icon"],
auth_method_config=patch_auth_event(
self.id, alt_auth_method
).get_public_config()
)
for alt_auth_method in self.alternative_auth_methods
]
Expand Down
27 changes: 18 additions & 9 deletions iam/authmethods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,26 @@ def get_patched_auth_event(auth_event, request):
# alternative authentication method
for alt_auth_method in alt_auth_methods:
if alt_auth_method['id'] == requested_alt_auth_method_id:
from api.models import AuthEvent
# obtain a new instance of patched_auth_event and patch it to
# not allow saving and change the extra_fields, auth_method and
# auth_method_config
patched_auth_event = AuthEvent.objects.get(pk=auth_event.id)
patched_auth_event.save = patched_auth_event_save
patched_auth_event.auth_method = alt_auth_method['auth_method_name']
patched_auth_event.auth_method_config = alt_auth_method['auth_method_config']
patched_auth_event.extra_fields = alt_auth_method['extra_fields']
patched_auth_event = patch_auth_event(
auth_event.id,
alt_auth_method
)
return (patched_auth_event, None)

def patch_auth_event(auth_event_id, alt_auth_method):
'''
obtain a new instance of patched_auth_event and patch it to
not allow saving and change the extra_fields, auth_method and
auth_method_config
'''
from api.models import AuthEvent
patched_auth_event = AuthEvent.objects.get(pk=auth_event_id)
patched_auth_event.save = patched_auth_event_save
patched_auth_event.auth_method = alt_auth_method['auth_method_name']
patched_auth_event.auth_method_config = alt_auth_method['auth_method_config']
patched_auth_event.extra_fields = alt_auth_method['extra_fields']
return patched_auth_event

def check_config(config, auth_method, data):
"""
Check config when creating an auth-event
Expand Down

0 comments on commit c57a25d

Please sign in to comment.