diff --git a/sso_edx_tp/backends/tp.py b/sso_edx_tp/backends/tp.py index 2c11648..4c33d81 100644 --- a/sso_edx_tp/backends/tp.py +++ b/sso_edx_tp/backends/tp.py @@ -43,6 +43,7 @@ class TpBackend(BaseOAuth2): EXTRA_DATA = [ ('refresh_token', 'refresh_token', True), ('expires_in', 'expires'), + ('gtm_id', 'gtm_id', True), ] PIPELINE = DEFAULT_AUTH_PIPELINE diff --git a/sso_edx_tp/context_processors.py b/sso_edx_tp/context_processors.py new file mode 100644 index 0000000..776f2ee --- /dev/null +++ b/sso_edx_tp/context_processors.py @@ -0,0 +1,16 @@ +from django.conf import settings + + +def edx_context(request): + gtm_id = None + if request.user.is_authenticated(): + items = request.user.social_auth.filter(provider__in=('sso_tp-oauth2', 'sso_tp_cms-oauth2')) + for item in items: + if isinstance(item.extra_data, dict) and isinstance(item.extra_data.get('gtm_id'), str) and item.extra_data.get('gtm_id'): + gtm_id = item.extra_data.get('gtm_id') + break + return { + 'USER_GTM_ID': gtm_id, + 'INCLUDE_ADDITIONAL_JS_CODE': getattr(settings, 'ADDITIONAL_JS_CODE', None), + } +