Skip to content

Commit

Permalink
Port PR #1037 by svvitale
Browse files Browse the repository at this point in the history
  • Loading branch information
omab committed Dec 3, 2016
1 parent 0de0e7d commit 2b8e06a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 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
- 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)
by iamkhush)
- Added Quizlet backend (port from [#1012](https://github.com/omab/python-social-auth/pull/1012)
Expand Down
32 changes: 32 additions & 0 deletions social_core/backends/mailchimp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from .oauth import BaseOAuth2


class MailChimpOAuth2(BaseOAuth2):
"""MailChimp OAuth2 authentication backend"""
name = 'mailchimp'
AUTHORIZATION_URL = 'https://login.mailchimp.com/oauth2/authorize'
ACCESS_TOKEN_URL = 'https://login.mailchimp.com/oauth2/token'
METADATA_URL = 'https://login.mailchimp.com/oauth2/metadata'
ACCESS_TOKEN_METHOD = 'POST'
STATE_PARAMETER = False
REDIRECT_STATE = False
ID_KEY = 'user_id'
EXTRA_DATA = [
('accountname', 'accountname'),
('api_endpoint', 'api_endpoint'),
('role', 'role'),
('login', 'login')
]

def get_user_details(self, response):
"""Return user details from a Mailchimp metadata response"""
return {
'username': response['login']['login_name'],
'email': response['login']['email']
}

def user_data(self, access_token, *args, **kwargs):
"""Loads user data and datacenter information from service"""
return self.get_json(self.METADATA_URL, headers={
'Authorization': 'OAuth ' + access_token
})

0 comments on commit 2b8e06a

Please sign in to comment.