-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #450 from SUNET/ft-new_auth
Security zone backend
- Loading branch information
Showing
74 changed files
with
2,363 additions
and
1,691 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from enum import unique, Enum | ||
|
||
__author__ = "lundberg" | ||
|
||
|
||
@unique | ||
class EduidAuthnContextClass(str, Enum): | ||
DIGG_LOA2 = "http://id.elegnamnden.se/loa/1.0/loa2" | ||
REFEDS_MFA = "https://refeds.org/profile/mfa" | ||
REFEDS_SFA = "https://refeds.org/profile/sfa" | ||
FIDO_U2F = "https://www.swamid.se/specs/id-fido-u2f-ce-transports" | ||
EDUID_MFA = "https://eduid.se/specs/mfa" | ||
PASSWORD_PT = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport" | ||
NOT_IMPLEMENTED = "not implemented" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,13 @@ | ||
import logging | ||
from typing import Optional | ||
from enum import unique | ||
|
||
from eduid.common.misc.timeutil import utc_now | ||
from eduid.userdb.credentials import Credential | ||
from eduid.webapp.common.authn.acs_enums import AuthnAcsAction | ||
from eduid.webapp.common.session import session | ||
from eduid.webapp.common.session.namespaces import SP_AuthnRequest | ||
from eduid.webapp.common.api.messages import TranslatableMsg | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def credential_used_to_authenticate(credential: Credential, max_age: int) -> bool: | ||
@unique | ||
class AuthnMsg(TranslatableMsg): | ||
""" | ||
Check if a particular credential was used to authenticate (using the eduID IdP and authn). | ||
Messages sent to the front end with information on the results of the | ||
attempted operations on the back end. | ||
""" | ||
logger.debug(f"Checking if credential {credential} has been used in the last {max_age} seconds") | ||
|
||
login = session.authn.sp.get_authn_for_action(AuthnAcsAction.login) | ||
reauthn = session.authn.sp.get_authn_for_action(AuthnAcsAction.reauthn) | ||
|
||
if _credential_recently_used(credential, login, max_age) or _credential_recently_used(credential, reauthn, max_age): | ||
return True | ||
return False | ||
|
||
|
||
def _credential_recently_used(credential: Credential, action: Optional[SP_AuthnRequest], max_age: int) -> bool: | ||
if action and credential.key in action.credentials_used: | ||
if action.authn_instant is not None: | ||
age = (utc_now() - action.authn_instant).total_seconds() | ||
if 0 < age < max_age: | ||
return True | ||
return False | ||
frontend_action_not_supported = "authn.frontend_action_not_supported" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from marshmallow import fields | ||
|
||
from eduid.webapp.common.api.schemas.base import EduidSchema, FluxStandardAction | ||
from eduid.webapp.common.api.schemas.csrf import CSRFRequestMixin, CSRFResponseMixin | ||
|
||
__author__ = "lundberg" | ||
|
||
|
||
class AuthnCommonRequestSchema(EduidSchema, CSRFRequestMixin): | ||
"""A verify request for either an identity or a credential proofing.""" | ||
|
||
frontend_action = fields.String(required=True) | ||
frontend_state = fields.String(required=False) | ||
method = fields.String(required=False) | ||
|
||
|
||
class AuthnCommonResponseSchema(FluxStandardAction): | ||
class AuthnCommonResponsePayload(EduidSchema, CSRFResponseMixin): | ||
location = fields.String(required=False) | ||
|
||
payload = fields.Nested(AuthnCommonResponsePayload) | ||
|
||
|
||
class AuthnStatusRequestSchema(EduidSchema, CSRFRequestMixin): | ||
authn_id = fields.String(required=False) | ||
|
||
|
||
class AuthnStatusResponseSchema(EduidSchema, CSRFResponseMixin): | ||
class StatusResponsePayload(EduidSchema, CSRFResponseMixin): | ||
authn_id = fields.String(required=False) | ||
frontend_action = fields.String(required=True) | ||
frontend_state = fields.String(required=False) | ||
method = fields.String(required=True) | ||
error = fields.Boolean(required=False) | ||
status = fields.String(required=False) | ||
|
||
payload = fields.Nested(StatusResponsePayload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,17 @@ | ||
from typing import Mapping | ||
from eduid.common.config.base import EduIDBaseAppConfig, ErrorsConfigMixin, FrontendActionMixin, Pysaml2SPConfigMixin | ||
from eduid.common.models.generic import HttpUrlStr | ||
|
||
from pydantic import Field | ||
|
||
from eduid.common.config.base import EduIDBaseAppConfig, ErrorsConfigMixin, Pysaml2SPConfigMixin | ||
|
||
|
||
class AuthnConfig(EduIDBaseAppConfig, ErrorsConfigMixin, Pysaml2SPConfigMixin): | ||
class AuthnConfig(EduIDBaseAppConfig, ErrorsConfigMixin, Pysaml2SPConfigMixin, FrontendActionMixin): | ||
""" | ||
Configuration for the authn app | ||
""" | ||
|
||
app_name: str = "authn" | ||
server_name: str = "authn" | ||
required_loa: Mapping[str, str] = Field( | ||
default={ | ||
"personal": "http://www.swamid.se/policy/assurance/al1", | ||
"helpdesk": "http://www.swamid.se/policy/assurance/al2", | ||
"admin": "http://www.swamid.se/policy/assurance/al3", | ||
} | ||
) | ||
available_loa: str = "http://www.swamid.se/policy/assurance/al1" | ||
signup_authn_success_redirect_url: str = "https://dashboard.eduid.se" | ||
signup_authn_failure_redirect_url: str = "https://dashboard.eduid.se" | ||
signup_authn_success_redirect_url: HttpUrlStr = "https://eduid.se/profile/" | ||
signup_authn_failure_redirect_url: HttpUrlStr = "https://eduid.se/profile/" | ||
fallback_frontend_action_redirect_url: HttpUrlStr = "https://eduid.se/profile/" | ||
saml2_login_redirect_url: str | ||
saml2_logout_redirect_url: str | ||
saml2_strip_saml_user_suffix: str | ||
|
||
token_service_url: str |
Oops, something went wrong.