1515
1616__author__ = 'Roland Hedberg'
1717
18- logger = logging .getLogger (__name__ )
18+ LOGGER = logging .getLogger (__name__ )
1919
2020"""
2121method call structure for Endpoints:
@@ -62,7 +62,7 @@ class Endpoint(object):
6262 request_placement = 'query'
6363 response_format = 'json'
6464 response_placement = 'body'
65- client_auth_method = ''
65+ client_authn_method = ''
6666
6767 def __init__ (self , endpoint_context , ** kwargs ):
6868 self .endpoint_context = endpoint_context
@@ -81,8 +81,8 @@ def parse_request(self, request, auth=None, **kwargs):
8181 :param kwargs: extra keyword arguments
8282 :return:
8383 """
84- logger .debug ("- {} -" .format (self .endpoint_name ))
85- logger .info ("Request: %s" % sanitize (request ))
84+ LOGGER .debug ("- {} -" .format (self .endpoint_name ))
85+ LOGGER .info ("Request: %s" % sanitize (request ))
8686
8787 if request :
8888 if isinstance (request , dict ):
@@ -108,7 +108,8 @@ def parse_request(self, request, auth=None, **kwargs):
108108 try :
109109 auth_info = self .client_authentication (req , auth , ** kwargs )
110110 except UnknownOrNoAuthnMethod :
111- if not self .client_auth_method :
111+ # If there is no required client authentication method
112+ if not self .client_authn_method :
112113 try :
113114 _client_id = req ['client_id' ]
114115 except KeyError :
@@ -138,7 +139,7 @@ def parse_request(self, request, auth=None, **kwargs):
138139 return self .error_cls (error = "invalid_request" ,
139140 error_description = "%s" % err )
140141
141- logger .info ("Parsed and verified request: %s" % sanitize (req ))
142+ LOGGER .info ("Parsed and verified request: %s" % sanitize (req ))
142143
143144 # Do any endpoint specific parsing
144145 return self .do_post_parse_request (req , _client_id , ** kwargs )
@@ -154,7 +155,13 @@ def client_authentication(self, request, auth=None, **kwargs):
154155 :return: client_id or raise an exception
155156 """
156157
157- return verify_client (self .endpoint_context , request , auth )
158+ authn_info = verify_client (self .endpoint_context , request , auth )
159+
160+ if authn_info ['method' ] not in self .client_authn_method :
161+ LOGGER .warning ("Wrong client authentication method was used" )
162+ raise UnknownOrNoAuthnMethod ("Wrong authn method" )
163+
164+ return authn_info
158165
159166 def do_post_parse_request (self , request , client_id = '' , ** kwargs ):
160167 for meth in self .post_parse_request :
@@ -197,7 +204,7 @@ def construct(self, response_args, request, **kwargs):
197204 """
198205 response_args = self .do_pre_construct (response_args , request , ** kwargs )
199206
200- # logger .debug("kwargs: %s" % sanitize(kwargs))
207+ # LOGGER .debug("kwargs: %s" % sanitize(kwargs))
201208 response = self .response_cls (** response_args )
202209
203210 return self .do_post_construct (response , request , ** kwargs )
0 commit comments