Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add authn options for more next responses #706

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion src/eduid/webapp/idp/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum, unique
from typing import Any

from saml2 import BINDING_HTTP_POST

Expand Down Expand Up @@ -67,7 +68,7 @@ def lookup_user(username: str, managed_account_allowed: bool = False) -> IdPUser
return current_app.userdb.lookup_user(username)


def create_saml_sp_response(saml_params: SAMLResponseParams) -> FluxData:
def create_saml_sp_response(saml_params: SAMLResponseParams, authn_options: dict[str, Any]) -> FluxData:
"""
Create a response to frontend that should be posted to the SP
"""
Expand All @@ -81,5 +82,6 @@ def create_saml_sp_response(saml_params: SAMLResponseParams) -> FluxData:
"target": saml_params.url,
"parameters": saml_params.post_params,
"missing_attributes": saml_params.missing_attributes,
"authn_options": authn_options,
},
)
17 changes: 10 additions & 7 deletions src/eduid/webapp/idp/views/next.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def next_view(ticket: LoginContext, sso_session: SSOSession | None) -> FluxData:
if _next.message == IdPMsg.aborted:
if isinstance(ticket, LoginContextSAML):
saml_params = cancel_saml_request(ticket, current_app.conf)
return create_saml_sp_response(saml_params=saml_params)
authn_options = _get_authn_options(ticket=ticket, sso_session=sso_session, eppn=None)
return create_saml_sp_response(saml_params=saml_params, authn_options=authn_options)
elif isinstance(ticket, LoginContextOtherDevice):
state = ticket.other_device_req
if state.state in [OtherDeviceState.NEW, OtherDeviceState.IN_PROGRESS, OtherDeviceState.AUTHENTICATED]:
Expand Down Expand Up @@ -78,7 +79,8 @@ def next_view(ticket: LoginContext, sso_session: SSOSession | None) -> FluxData:
if _next.message == IdPMsg.assurance_failure:
if isinstance(ticket, LoginContextSAML):
saml_params = authn_context_class_not_supported(ticket, current_app.conf)
return create_saml_sp_response(saml_params=saml_params)
authn_options = _get_authn_options(ticket=ticket, sso_session=sso_session, eppn=None)
return create_saml_sp_response(saml_params=saml_params, authn_options=authn_options)
current_app.logger.error(f"Don't know how to send error response for request {ticket}")
return error_response(message=IdPMsg.general_failure)

Expand All @@ -100,7 +102,7 @@ def next_view(ticket: LoginContext, sso_session: SSOSession | None) -> FluxData:
_payload = {
"action": IdPAction.OTHER_DEVICE.value,
"target": url_for("other_device.use_other_1", _external=True),
"authn_options": _get_authn_options(ticket, sso_session, required_user.eppn),
"authn_options": _get_authn_options(ticket=ticket, sso_session=sso_session, eppn=required_user.eppn),
"service_info": _get_service_info(ticket),
}

Expand All @@ -113,7 +115,7 @@ def next_view(ticket: LoginContext, sso_session: SSOSession | None) -> FluxData:
_payload = {
"action": IdPAction.PWAUTH.value,
"target": url_for("pw_auth.pw_auth", _external=True),
"authn_options": _get_authn_options(ticket, sso_session, required_user.eppn),
"authn_options": _get_authn_options(ticket=ticket, sso_session=sso_session, eppn=required_user.eppn),
"service_info": _get_service_info(ticket),
}

Expand All @@ -128,7 +130,7 @@ def next_view(ticket: LoginContext, sso_session: SSOSession | None) -> FluxData:
payload={
"action": IdPAction.MFA.value,
"target": url_for("mfa_auth.mfa_auth", _external=True),
"authn_options": _get_authn_options(ticket, sso_session, required_user.eppn),
"authn_options": _get_authn_options(ticket=ticket, sso_session=sso_session, eppn=required_user.eppn),
"service_info": _get_service_info(ticket),
},
)
Expand All @@ -139,7 +141,7 @@ def next_view(ticket: LoginContext, sso_session: SSOSession | None) -> FluxData:
payload={
"action": IdPAction.TOU.value,
"target": url_for("tou.tou", _external=True),
"authn_options": _get_authn_options(ticket, sso_session, required_user.eppn),
"authn_options": _get_authn_options(ticket=ticket, sso_session=sso_session, eppn=required_user.eppn),
},
)

Expand Down Expand Up @@ -186,7 +188,8 @@ def next_view(ticket: LoginContext, sso_session: SSOSession | None) -> FluxData:

if isinstance(ticket, LoginContextSAML):
saml_params = sso.get_response_params(_next.authn_info, ticket, user)
return create_saml_sp_response(saml_params=saml_params)
authn_options = _get_authn_options(ticket=ticket, sso_session=sso_session, eppn=required_user.eppn)
return create_saml_sp_response(saml_params=saml_params, authn_options=authn_options)
elif isinstance(ticket, LoginContextOtherDevice):
if not ticket.is_other_device_2:
# We shouldn't be able to get here, but this clearly shows where this code runs
Expand Down
Loading