From cf50d046fa0f0ffad8822bf650234be0af220080 Mon Sep 17 00:00:00 2001 From: lpm0073 Date: Mon, 3 Oct 2022 23:45:40 -0500 Subject: [PATCH] make user_data() return the same dict as get_user_details() --- wp_oauth_backend/wp_oauth.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/wp_oauth_backend/wp_oauth.py b/wp_oauth_backend/wp_oauth.py index 0035827..01dcef1 100644 --- a/wp_oauth_backend/wp_oauth.py +++ b/wp_oauth_backend/wp_oauth.py @@ -8,10 +8,12 @@ logger = getLogger(__name__) class WPOAuth2(BaseOAuth2): - """WP OAuth authentication backend""" + name = 'wp-oauth' - SOCIAL_AUTH_SANITIZE_REDIRECTS = False + + # https://python-social-auth.readthedocs.io/en/latest/configuration/settings.html + SOCIAL_AUTH_SANITIZE_REDIRECTS = True # for redirect domain to exactly match the initiating domain. ACCESS_TOKEN_METHOD = 'POST' SCOPE_SEPARATOR = ',' BASE_URL = "https://stepwisemath.ai" @@ -83,16 +85,17 @@ class WPOAuth2(BaseOAuth2): def user_data(self, access_token, *args, **kwargs) -> dict: """Loads user data from service""" + url = f'{self.USER_QUERY}?' + urlencode({ 'access_token': access_token }) + logger.info("user_data() url: {url}".format(url=url)) + try: response = json.loads(self.urlopen(url)) - logger.info('user_data() - response: {response}'.format( - response=json.dumps(response, sort_keys=True, indent=4) - )) - return response + user_details = self.get_user_details(response) + return user_details except ValueError as e: logger.error('user_data() did not work: {err}'.format(err=e)) return None