Permalink
Browse files

add coinbase oauth

  • Loading branch information...
FloorLamp committed Nov 23, 2013
1 parent cc6970b commit 442ca5ec3ec140268dc34e589a8277d81547478f
@@ -127,6 +127,7 @@
'social.backends.belgiumeid.BelgiumEIDOpenId',
'social.backends.bitbucket.BitbucketOAuth',
'social.backends.box.BoxOAuth2',
'social.backends.coinbase.CoinbaseOAuth2',
'social.backends.dailymotion.DailymotionOAuth2',
'social.backends.disqus.DisqusOAuth2',
'social.backends.douban.DoubanOAuth2',
@@ -10,6 +10,7 @@
<a href="{% url 'social:begin' 'belgiumeid' %}">BelgiumEID OpenId</a> <br />
<a href="{% url 'social:begin' 'bitbucket' %}">Bitbucket OAuth1</a> <br />
<a href="{% url 'social:begin' 'box' %}">Box.net OAuth2</a> <br />
<a href="{% url 'social:begin' 'coinbase' %}">Coinbase OAuth2</a> <br />
<a href="{% url 'social:begin' 'dailymotion' %}">Dailymotion OAuth2</a> <br />
<a href="{% url 'social:begin' 'disqus' %}">Disqus OAuth2</a> <br />
<a href="{% url 'social:begin' 'douban-oauth2' %}">Douban OAuth2</a> <br />
@@ -11,6 +11,7 @@
from social.tests.backends.test_bitbucket import *
from social.tests.backends.test_box import *
from social.tests.backends.test_broken import *
from social.tests.backends.test_coinbase import *
from social.tests.backends.test_dailymotion import *
from social.tests.backends.test_disqus import *
from social.tests.backends.test_dropbox import *
@@ -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})
@@ -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()

0 comments on commit 442ca5e

Please sign in to comment.