6
6
7
7
from idpyoidc .server .user_authn .authn_context import UNSPECIFIED
8
8
9
+ import satosa .logging_util as lu
9
10
from satosa .backends .base import BackendModule
11
+ from satosa .exception import SATOSAAuthenticationError
10
12
from satosa .internal import AuthenticationInformation
11
13
from satosa .internal import InternalData
12
14
@@ -83,6 +85,23 @@ def register_endpoints(self):
83
85
84
86
return self .client .context .claims .get_usage ('authorization_endpoint' )
85
87
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
+
86
105
def _authn_response (self , context ):
87
106
"""
88
107
Handles the authentication response from the AS.
@@ -95,6 +114,7 @@ def _authn_response(self, context):
95
114
"""
96
115
97
116
_info = self .client .finalize (context .request )
117
+ self ._check_error_response (_info , context )
98
118
99
119
try :
100
120
auth_info = self .auth_info (context .request )
0 commit comments