Skip to content

Commit 35b54a1

Browse files
committed
feat: introduce logging to the backend classes
1 parent bb3d0e9 commit 35b54a1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

social_core/backends/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import requests
77

88
from social_core.exceptions import AuthConnectionError, AuthUnknownError
9-
from social_core.utils import module_member, parse_qs, user_agent
9+
from social_core.utils import module_member, parse_qs, social_logger, user_agent
1010

1111
if TYPE_CHECKING:
1212
from collections.abc import Mapping
@@ -33,6 +33,12 @@ def __init__(self, strategy, redirect_uri=None) -> None:
3333
self.data = self.strategy.request_data()
3434
self.redirect_uri = self.strategy.absolute_uri(self.redirect_uri)
3535

36+
def log_debug(self, message, *args) -> None:
37+
social_logger.debug(f"{self.name}: {message}", *args)
38+
39+
def log_warning(self, message, *args) -> None:
40+
social_logger.warning(f"{self.name}: {message}", *args)
41+
3642
def setting(self, name, default=None):
3743
"""Return setting value from strategy"""
3844
return self.strategy.setting(name, default=default, backend=self)

social_core/backends/cas.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
implementation and the standard OIDC implementation in Python Social Auth.
88
"""
99

10-
import logging
11-
1210
from .open_id_connect import OpenIdConnectAuth
1311

14-
logger = logging.getLogger("social")
15-
1612

1713
class CASOpenIdConnectAuth(OpenIdConnectAuth):
1814
"""
@@ -33,25 +29,23 @@ class CASOpenIdConnectAuth(OpenIdConnectAuth):
3329

3430
def oidc_endpoint(self):
3531
endpoint = self.setting("OIDC_ENDPOINT", self.OIDC_ENDPOINT)
36-
logger.debug("backend: CAS, endpoint: %s", endpoint)
32+
self.log_debug("endpoint: %s", endpoint)
3733
return endpoint
3834

3935
def get_user_id(self, details, response):
40-
logger.debug(
41-
"backend: CAS, method: get_user_id, details: %s, %s", details, response
42-
)
36+
self.log_debug("method: get_user_id, details: %s, %s", details, response)
4337
return details.get("username")
4438

4539
def user_data(self, access_token, *args, **kwargs):
4640
data = self.get_json(
4741
self.userinfo_url(), headers={"Authorization": f"Bearer {access_token}"}
4842
)
49-
logger.debug("backend: CAS, user_data: %s", data)
43+
self.log_debug("user_data: %s", data)
5044
return data.get("attributes", {})
5145

5246
def get_user_details(self, response):
5347
username_key = self.setting("USERNAME_KEY", self.USERNAME_KEY)
54-
logger.debug("backend: CAS, username_key: %s", username_key)
48+
self.log_debug("username_key: %s", username_key)
5549
attributes = self.user_data(response.get("access_token"))
5650
return {
5751
"username": attributes.get(username_key),

0 commit comments

Comments
 (0)