make user_data() return the same dict as get_user_details()
This commit is contained in:
		@@ -8,10 +8,12 @@ logger = getLogger(__name__)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class WPOAuth2(BaseOAuth2):
 | 
					class WPOAuth2(BaseOAuth2):
 | 
				
			||||||
 | 
					 | 
				
			||||||
    """WP OAuth authentication backend"""
 | 
					    """WP OAuth authentication backend"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    name = 'wp-oauth'
 | 
					    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'
 | 
					    ACCESS_TOKEN_METHOD = 'POST'
 | 
				
			||||||
    SCOPE_SEPARATOR = ','
 | 
					    SCOPE_SEPARATOR = ','
 | 
				
			||||||
    BASE_URL = "https://stepwisemath.ai"
 | 
					    BASE_URL = "https://stepwisemath.ai"
 | 
				
			||||||
@@ -83,16 +85,17 @@ class WPOAuth2(BaseOAuth2):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def user_data(self, access_token, *args, **kwargs) -> dict:
 | 
					    def user_data(self, access_token, *args, **kwargs) -> dict:
 | 
				
			||||||
        """Loads user data from service"""
 | 
					        """Loads user data from service"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        url = f'{self.USER_QUERY}?' + urlencode({
 | 
					        url = f'{self.USER_QUERY}?' + urlencode({
 | 
				
			||||||
            'access_token': access_token
 | 
					            'access_token': access_token
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        logger.info("user_data() url: {url}".format(url=url))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            response = json.loads(self.urlopen(url))
 | 
					            response = json.loads(self.urlopen(url))
 | 
				
			||||||
            logger.info('user_data() -  response: {response}'.format(
 | 
					            user_details = self.get_user_details(response)
 | 
				
			||||||
                response=json.dumps(response, sort_keys=True, indent=4)
 | 
					            return user_details
 | 
				
			||||||
                ))
 | 
					 | 
				
			||||||
            return response
 | 
					 | 
				
			||||||
        except ValueError as e:
 | 
					        except ValueError as e:
 | 
				
			||||||
            logger.error('user_data() did not work: {err}'.format(err=e))
 | 
					            logger.error('user_data() did not work: {err}'.format(err=e))
 | 
				
			||||||
            return None
 | 
					            return None
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user