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

Fix mfa response 396 #502

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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: 2 additions & 2 deletions app/api/auth/router_mfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async def two_factor_protocol(
)
return MFAChallengeResponse(status="bypass", message="")

except MultifactorAPI.MultifactorError:
except MultifactorAPI.MultifactorError as error:
if network_policy.bypass_service_failure:
await create_and_set_session_key(
user,
Expand All @@ -296,7 +296,7 @@ async def two_factor_protocol(
logger.critical(f"API error {traceback.format_exc()}")
raise HTTPException(
status.HTTP_406_NOT_ACCEPTABLE,
"Multifactor error",
str(error),
)

return MFAChallengeResponse(status="pending", message=redirect_url)
11 changes: 9 additions & 2 deletions app/ldap_protocol/multifactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,19 @@ async def get_create_mfa(
if response.status_code == 401:
raise self.MFAMissconfiguredError("API Key or Secret is invalid")

if response.status_code != 200:
raise self.MultifactorError("Status error")
if response.status_code == 403:
raise self.MultifactorError("Incorrect resource")

if response.status_code == 429:
raise self.MultifactorError("API calls quota exceeded")

try:
response_data = response.json()
log_mfa.info(response_data)

if response_data.get("success") is False:
raise self.MultifactorError(response_data.get("message"))

return response_data["model"]["url"]
except (JSONDecodeError, KeyError) as err:
raise self.MultifactorError(f"MFA API error: {err}") from err
Expand Down