-
-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from social_core.backends.oauth import BaseOAuth2 | ||
|
||
class MusicBrainzOAuth2(BaseOAuth2): | ||
"""MusicBrainz OAuth authentication backend""" | ||
name = 'musicbrainz' | ||
AUTHORIZATION_URL = 'https://musicbrainz.org/oauth2/authorize' | ||
ACCESS_TOKEN_URL = 'https://musicbrainz.org/oauth2/token' | ||
ACCESS_TOKEN_METHOD = 'POST' | ||
ID_KEY = 'metabrainz_user_id' | ||
DEFAULT_SCOPE = ['profile', 'email'] | ||
SCOPE_SEPARATOR = ' ' | ||
REDIRECT_STATE = False | ||
EXTRA_DATA = [ | ||
('metabrainz_user_id', 'id'), | ||
('expires_in', 'expires'), | ||
] | ||
|
||
def get_user_details(self, response): | ||
"""Return user details from MusicBrainz account""" | ||
return {'username': response.get('sub'), | ||
'email': response.get('email') or '', | ||
'first_name': response.get('sub')} | ||
|
||
def user_data(self, access_token, *args, **kwargs): | ||
"""Loads user data from service""" | ||
return self.get_json('https://musicbrainz.org/oauth2/userinfo', params={ | ||
'access_token': access_token | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
|
||
from httpretty import HTTPretty | ||
|
||
from ...exceptions import AuthFailed | ||
from .oauth import OAuth2Test | ||
|
||
|
||
class MusicBrainzAuth2Test(OAuth2Test): | ||
backend_path = 'social_core.backends.musicbrainz.MusicBrainzOAuth2' | ||
user_data_url = 'https://musicbrainz.org/oauth2/userinfo' | ||
expected_username = 'foobar' | ||
access_token_body = json.dumps({ | ||
'access_token': 'GjtKfJS6G4lupbQcCOiTKo4HcLXUgI1p', | ||
'expires_in': 3600, | ||
'token_type': 'Bearer', | ||
'refresh_token': 'GjSCBBjp4fnbE0AKo3uFu9qq9K2fFm4u' | ||
}) | ||
user_data_body = json.dumps({ | ||
'sub': 'foobar', | ||
'email': 'foo@bar.com', | ||
}) | ||
|
||
def test_login(self): | ||
self.do_login() | ||
|
||
def test_partial_pipeline(self): | ||
self.do_partial_pipeline() |