Skip to content

Commit dba92f8

Browse files
rohec00kiemon5ter
authored andcommitted
Added error message handling.
1 parent 47638a7 commit dba92f8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/satosa/backends/idpy_oidc.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
from idpyoidc.server.user_authn.authn_context import UNSPECIFIED
88

9+
import satosa.logging_util as lu
910
from satosa.backends.base import BackendModule
11+
from satosa.exception import SATOSAAuthenticationError
1012
from satosa.internal import AuthenticationInformation
1113
from satosa.internal import InternalData
1214

@@ -83,6 +85,23 @@ def register_endpoints(self):
8385

8486
return self.client.context.claims.get_usage('authorization_endpoint')
8587

88+
def _check_error_response(self, response, context):
89+
"""
90+
Check if the response is an error response.
91+
:param response: the response from finalize()
92+
:type response: oic.oic.message
93+
:raise SATOSAAuthenticationError: if the response is an OAuth error response
94+
"""
95+
if "error" in response:
96+
msg = "{name} error: {error} {description}".format(
97+
name=type(response).__name__,
98+
error=response["error"],
99+
description=response.get("error_description", ""),
100+
)
101+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
102+
logger.debug(logline)
103+
raise SATOSAAuthenticationError(context.state, "Access denied")
104+
86105
def _authn_response(self, context):
87106
"""
88107
Handles the authentication response from the AS.
@@ -95,6 +114,7 @@ def _authn_response(self, context):
95114
"""
96115

97116
_info = self.client.finalize(context.request)
117+
self._check_error_response(_info, context)
98118

99119
try:
100120
auth_info = self.auth_info(context.request)

0 commit comments

Comments
 (0)