Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ or current ones extended):
* Livejournal_ OpenId
* LoginRadius_ OAuth2 and Application Auth
* Mailru_ OAuth2
* MapMyFitness_ OAuth2
* Mendeley_ OAuth1 http://mendeley.com
* Mixcloud_ OAuth2
* `Mozilla Persona`_
Expand Down Expand Up @@ -231,6 +232,7 @@ check `django-social-auth LICENSE`_ for details:
.. _Live: https://live.com
.. _Livejournal: http://livejournal.com
.. _Mailru: https://mail.ru
.. _MapMyFitness: http://www.mapmyfitness.com/
.. _Mixcloud: https://www.mixcloud.com
.. _Mozilla Persona: http://www.mozilla.org/persona/
.. _Odnoklassniki: http://www.odnoklassniki.ru
Expand Down
1 change: 1 addition & 0 deletions docs/backends/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Social backends
live
loginradius
mailru
mapmyfitness
mendeley
mixcloud
odnoklassnikiru
Expand Down
13 changes: 13 additions & 0 deletions docs/backends/mapmyfitness.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
MapMyFitness
=========

MapMyFitness uses OAuth v2 for authentication.

- Register a new application at the `MapMyFitness API`_, and

- fill ``key`` and ``secret`` values in the settings::

SOCIAL_AUTH_MAPMYFITNESS_KEY = ''
SOCIAL_AUTH_MAPMYFITNESS_SECRET = ''

.. _MapMyFitness API: https://www.mapmyapi.com
48 changes: 48 additions & 0 deletions social/backends/mapmyfitness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
MapMyFitness OAuth2 backend, docs at:
http://psa.matiasaguirre.net/docs/backends/mapmyfitness.html
"""
from social.backends.oauth import BaseOAuth2


class MapMyFitnessOAuth2(BaseOAuth2):
"""MapMyFitness OAuth authentication backend"""
name = 'mapmyfitness'
AUTHORIZATION_URL = 'https://www.mapmyfitness.com/v7.0/oauth2/authorize'
ACCESS_TOKEN_URL = 'https://oauth2-api.mapmyapi.com/v7.0/oauth2/access_token'
REQUEST_TOKEN_METHOD = 'POST'
ACCESS_TOKEN_METHOD = 'POST'
REDIRECT_STATE = False
EXTRA_DATA = [
('refresh_token', 'refresh_token'),
]

def auth_headers(self):
key = self.get_key_and_secret()[0]
return {
'Api-Key': key
}

def get_user_id(self, details, response):
return response['id']

def get_user_details(self, response):
first = response.get('first_name', '')
last = response.get('last_name', '')
full = (first + last).strip()
return {
'username': response['username'],
'email': response['email'],
'fullname': full,
'first_name': first,
'last_name': last,
}

def user_data(self, access_token, *args, **kwargs):
key = self.get_key_and_secret()[0]
url = 'https://oauth2-api.mapmyapi.com/v7.0/user/self/'
headers = {
'Authorization': 'Bearer {0}'.format(access_token),
'Api-Key': key
}
return self.get_json(url, headers=headers)
153 changes: 153 additions & 0 deletions social/tests/backends/test_mapmyfitness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import json

from social.tests.backends.oauth import OAuth2Test


class MapMyFitnessOAuth2Test(OAuth2Test):
backend_path = 'social.backends.mapmyfitness.MapMyFitnessOAuth2'
user_data_url = 'https://oauth2-api.mapmyapi.com/v7.0/user/self/'
expected_username = 'FredFlinstone'
access_token_body = json.dumps({
'access_token': 'foobar',
'token_type': 'Bearer',
'expires_in': 4000000,
'refresh_token': 'bambaz',
'scope': 'read'
})
user_data_body = json.dumps({
'last_name': 'Flinstone',
'weight': 91.17206637,
'communication': {
'promotions': True,
'newsletter': True,
'system_messages': True
},
'height': 1.778,
'token_type': 'Bearer',
'id': 112233,
'date_joined': '2011-08-26T06:06:19+00:00',
'first_name': 'Fred',
'display_name': 'Fred Flinstone',
'display_measurement_system': 'imperial',
'expires_in': 4000000,
'_links': {
'stats': [
{
'href': '/v7.0/user_stats/112233/?aggregate_by_period=month',
'id': '112233',
'name': 'month'
},
{
'href': '/v7.0/user_stats/112233/?aggregate_by_period=year',
'id': '112233',
'name': 'year'
},
{
'href': '/v7.0/user_stats/112233/?aggregate_by_period=day',
'id': '112233',
'name': 'day'
},
{
'href': '/v7.0/user_stats/112233/?aggregate_by_period=week',
'id': '112233',
'name': 'week'
},
{
'href': '/v7.0/user_stats/112233/?aggregate_by_period=lifetime',
'id': '112233',
'name': 'lifetime'
}
],
'friendships': [
{
'href': '/v7.0/friendship/?from_user=112233'
}
],
'privacy': [
{
'href': '/v7.0/privacy_option/3/',
'id': '3',
'name': 'profile'
},
{
'href': '/v7.0/privacy_option/3/',
'id': '3',
'name': 'workout'
},
{
'href': '/v7.0/privacy_option/3/',
'id': '3',
'name': 'activity_feed'
},
{
'href': '/v7.0/privacy_option/1/',
'id': '1',
'name': 'food_log'
},
{
'href': '/v7.0/privacy_option/3/',
'id': '3',
'name': 'email_search'
},
{
'href': '/v7.0/privacy_option/3/',
'id': '3',
'name': 'route'
}
],
'image': [
{
'href': '/v7.0/user_profile_photo/112233/',
'id': '112233',
'name': 'user_profile_photo'
}
],
'documentation': [
{
'href': 'https://www.mapmyapi.com/docs/User'
}
],
'workouts': [
{
'href': '/v7.0/workout/?user=112233&order_by=-start_datetime'
}
],
'deactivation': [
{
'href': '/v7.0/user_deactivation/'
}
],
'self': [
{
'href': '/v7.0/user/112233/',
'id': '112233'
}
]
},
'location': {
'country': 'US',
'region': 'NC',
'locality': 'Bedrock',
'address': '150 Dinosaur Ln'
},
'last_login': '2014-02-23T22:36:52+00:00',
'email': 'fredflinstone@gmail.com',
'username': 'FredFlinstone',
'sharing': {
'twitter': False,
'facebook': False
},
'scope': 'read',
'refresh_token': 'bambaz',
'last_initial': 'S.',
'access_token': 'foobar',
'gender': 'M',
'time_zone': 'America/Denver',
'birthdate': '1983-04-15'
})

def test_login(self):
self.do_login()

def test_partial_pipeline(self):
self.do_partial_pipeline()