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
5 changed files
with
79 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
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
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
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,29 @@ | ||
from social.backends.oauth import BaseOAuth2 | ||
|
||
|
||
class CoinbaseOAuth2(BaseOAuth2): | ||
name = 'coinbase' | ||
SCOPE_SEPARATOR = '+' | ||
DEFAULT_SCOPE = ['balance'] | ||
AUTHORIZATION_URL = 'https://coinbase.com/oauth/authorize' | ||
ACCESS_TOKEN_URL = 'https://coinbase.com/oauth/token' | ||
ACCESS_TOKEN_METHOD = 'POST' | ||
REDIRECT_STATE = False | ||
|
||
def get_user_details(self, response): | ||
"""Return user details from Coinbase account""" | ||
user_data = response['users'][0]['user'] | ||
name = user_data['name'] | ||
name_split = name.split() | ||
first_name = name_split[0] | ||
last_name = name_split[1] | ||
email = user_data.get('email', '') | ||
return {'username': name, | ||
'first_name': first_name, | ||
'last_name': last_name, | ||
'email': email} | ||
|
||
def user_data(self, access_token, *args, **kwargs): | ||
"""Loads user data from service""" | ||
return self.get_json('https://coinbase.com/api/v1/users', | ||
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,47 @@ | ||
import json | ||
|
||
from social.tests.backends.oauth import OAuth2Test | ||
|
||
|
||
class CoinbaseOAuth2Test(OAuth2Test): | ||
backend_path = 'social.backends.coinbase.CoinbaseOAuth2' | ||
user_data_url = 'https://coinbase.com/api/v1/users' | ||
expected_username = 'SatoshiNakamoto' | ||
access_token_body = json.dumps({ | ||
'access_token': 'foobar', | ||
'token_type': 'bearer' | ||
}) | ||
user_data_body = json.dumps({ | ||
'users': [ | ||
{ | ||
'user': { | ||
'id': "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", | ||
'name': "Satoshi Nakamoto", | ||
'email': "satoshi@nakamoto.com", | ||
'pin': None, | ||
'time_zone': "Eastern Time (US & Canada)", | ||
'native_currency': "USD", | ||
'buy_level': 2, | ||
'sell_level': 2, | ||
'balance': { | ||
'amount': "1000000", | ||
'currency': "BTC" | ||
}, | ||
'buy_limit': { | ||
'amount': "50.00000000", | ||
'currency': "BTC" | ||
}, | ||
'sell_limit': { | ||
'amount': "50.00000000", | ||
'currency': "BTC" | ||
} | ||
} | ||
} | ||
] | ||
}) | ||
|
||
def test_login(self): | ||
self.do_login() | ||
|
||
def test_partial_pipeline(self): | ||
self.do_partial_pipeline() |