only do dict comparisons if not tainted

This commit is contained in:
lpm0073 2022-10-05 19:47:46 -05:00
parent cb78347ed2
commit 53f530c0af

View File

@ -152,34 +152,35 @@ class StepwiseMathWPOAuth2(BaseOAuth2):
)) ))
tainted = True tainted = True
# a def in the third_party_auth pipeline list calls get_user_details() after its already if not tainted:
# been called once. i don't know why. but, it passes the original get_user_details() dict # a def in the third_party_auth pipeline list calls get_user_details() after its already
# enhanced with additional token-related keys. if we receive this modified dict then we # been called once. i don't know why. but, it passes the original get_user_details() dict
# should pass it along to the next defs in the pipeline. # enhanced with additional token-related keys. if we receive this modified dict then we
# # should pass it along to the next defs in the pipeline.
# If most of the original keys (see dict definition below) exist in the response object #
# then we can assume that this is our case. # If most of the original keys (see dict definition below) exist in the response object
qc_keys = ['id', 'date_joined', 'email', 'first_name', 'fullname', 'is_staff', 'is_superuser', 'last_name', 'username'] # then we can assume that this is our case.
if all(key in response for key in qc_keys): qc_keys = ['id', 'date_joined', 'email', 'first_name', 'fullname', 'is_staff', 'is_superuser', 'last_name', 'username']
if VERBOSE_LOGGING: if all(key in response for key in qc_keys):
logger.info('get_user_details() - detected an enhanced get_user_details() dict in the response: {response}'.format( if VERBOSE_LOGGING:
response=json.dumps(response, sort_keys=True, indent=4) logger.info('get_user_details() - detected an enhanced get_user_details() dict in the response: {response}'.format(
)) response=json.dumps(response, sort_keys=True, indent=4)
return response ))
return response
# otherwise we pobably received the default response from the oauth provider based on # otherwise we pobably received the default response from the oauth provider based on
# the scopes 'basic' 'email' 'profile'. We'll check a few of the most important keys to see # the scopes 'basic' 'email' 'profile'. We'll check a few of the most important keys to see
# if they exist. # if they exist.
if ('ID' not in response.keys()) or ('user_email' not in response.keys()) or ('user_login' not in response.keys()): if ('ID' not in response.keys()) or ('user_email' not in response.keys()) or ('user_login' not in response.keys()):
logger.warning('get_user_details() - response object is missing one or more required keys: {response}'.format( logger.warning('get_user_details() - response object is missing one or more required keys: {response}'.format(
response=json.dumps(response, sort_keys=True, indent=4)
))
tainted = True
else:
if VERBOSE_LOGGING:
logger.info('get_user_details() - start. response: {response}'.format(
response=json.dumps(response, sort_keys=True, indent=4) response=json.dumps(response, sort_keys=True, indent=4)
)) ))
tainted = True
else:
if VERBOSE_LOGGING:
logger.info('get_user_details() - start. response: {response}'.format(
response=json.dumps(response, sort_keys=True, indent=4)
))
if tainted and self.user_details: if tainted and self.user_details:
logger.warning('get_user_details() - returning cached results. user_details: {user_details}'.format( logger.warning('get_user_details() - returning cached results. user_details: {user_details}'.format(