Skip to content

Commit

Permalink
Port PR #1019 by keattang
Browse files Browse the repository at this point in the history
  • Loading branch information
omab committed Dec 4, 2016
1 parent 155f77d commit 0930a7d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased](https://github.com/python-social-auth/social-core/commits/master)

### Added
- Added the ability to specify a pipeline on a per backend basis (port from [#1019](https://github.com/omab/python-social-auth/pull/1019)
by keattang)
- Add support for MailChimp as an OAuth v2 backend (port from [#1037](https://github.com/omab/python-social-auth/pull/1037)
by svvitale)
- Added Shimmering backend (port from [#1054](https://github.com/omab/python-social-auth/pull/1054)
Expand Down
4 changes: 2 additions & 2 deletions social_core/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def authenticate(self, *args, **kwargs):
self.strategy = self.strategy or kwargs.get('strategy')
self.redirect_uri = self.redirect_uri or kwargs.get('redirect_uri')
self.data = self.strategy.request_data()
pipeline = self.strategy.get_pipeline()
pipeline = self.strategy.get_pipeline(self)
kwargs.setdefault('is_new', False)
if 'pipeline_index' in kwargs:
pipeline = pipeline[kwargs['pipeline_index']:]
Expand All @@ -93,7 +93,7 @@ def pipeline(self, pipeline, pipeline_index=0, *args, **kwargs):
return user

def disconnect(self, *args, **kwargs):
pipeline = self.strategy.get_disconnect_pipeline()
pipeline = self.strategy.get_disconnect_pipeline(self)
if 'pipeline_index' in kwargs:
pipeline = pipeline[kwargs['pipeline_index']:]
kwargs['name'] = self.name
Expand Down
14 changes: 9 additions & 5 deletions social_core/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ def clean_partial_pipeline(self, name='partial_pipeline'):
def openid_store(self):
return OpenIdStore(self)

def get_pipeline(self):
return self.setting('PIPELINE', DEFAULT_AUTH_PIPELINE)

def get_disconnect_pipeline(self):
return self.setting('DISCONNECT_PIPELINE', DEFAULT_DISCONNECT_PIPELINE)
def get_pipeline(self, backend=None):
return self.setting('PIPELINE', DEFAULT_AUTH_PIPELINE, backend)

def get_disconnect_pipeline(self, backend=None):
return self.setting(
'DISCONNECT_PIPELINE',
DEFAULT_DISCONNECT_PIPELINE,
backend
)

def random_string(self, length=12, chars=ALLOWED_CHARS):
# Implementation borrowed from django 1.4
Expand Down
29 changes: 17 additions & 12 deletions social_core/tests/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,20 @@ def authenticate(self, *args, **kwargs):
self.session_set('username', user.username)
return user

def get_pipeline(self):
return self.setting('PIPELINE', (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details'))
def get_pipeline(self, backend=None):
return self.setting(
'PIPELINE',
(
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details'
),
backend
)

0 comments on commit 0930a7d

Please sign in to comment.