From 6bf9d856c8e4cc4c1a72f67158468f8c94e3fca1 Mon Sep 17 00:00:00 2001 From: Troy Sankey Date: Thu, 11 Jul 2019 13:44:21 -0400 Subject: [PATCH] Add EdXOAuth2.auth_complete_signal on auth_complete() Also, version bumped to 2.0.2. This is part of the DOP->DOT migration. --- auth_backends/__init__.py | 2 +- auth_backends/backends.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auth_backends/__init__.py b/auth_backends/__init__.py index e936deb9..72786b9e 100644 --- a/auth_backends/__init__.py +++ b/auth_backends/__init__.py @@ -3,4 +3,4 @@ These package is designed to be used primarily with Open edX Django projects, but should be compatible with non-edX projects as well. """ -__version__ = '2.0.1' # pragma: no cover +__version__ = '2.0.2' # pragma: no cover diff --git a/auth_backends/backends.py b/auth_backends/backends.py index ae99b57b..e76b11c4 100644 --- a/auth_backends/backends.py +++ b/auth_backends/backends.py @@ -267,6 +267,9 @@ class EdXOAuth2(EdXBackendMixin, BaseOAuth2): 'user_id': 'user_id', }) + # This signal is fired after the user has successfully logged in. + auth_complete_signal = Signal(providing_args=['user']) + @property def logout_url(self): if self.setting('LOGOUT_REDIRECT_URL'): @@ -295,6 +298,16 @@ def auth_complete_params(self, state=None): params['token_type'] = 'jwt' return params + def auth_complete(self, *args, **kwargs): + """ + This method is overwritten to emit the `EdXOAuth2.auth_complete_signal` signal. + """ + # WARNING: During testing, the user model class is `social_core.tests.models.User`, + # not the model specified for the application. + user = super(EdXOAuth2, self).auth_complete(*args, **kwargs) + self.auth_complete_signal.send(sender=self.__class__, user=user) + return user + def user_data(self, access_token, *args, **kwargs): decoded_access_token = jwt.decode(access_token, verify=False)