66
77from idpyoidc .server .user_authn .authn_context import UNSPECIFIED
88
9+ import satosa .logging_util as lu
910from satosa .backends .base import BackendModule
11+ from satosa .exception import SATOSAAuthenticationError
1012from satosa .internal import AuthenticationInformation
1113from 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