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 @@ -60,6 +60,7 @@ or current ones extended):
* BelgiumEIDOpenId_ OpenId https://www.e-contract.be/
* Bitbucket_ OAuth1
* Box_ OAuth2
* Clef_ OAuth2
* Dailymotion_ OAuth2
* Disqus_ OAuth2
* Douban_ OAuth1 and OAuth2
Expand Down Expand Up @@ -214,6 +215,7 @@ check `django-social-auth LICENSE`_ for details:
.. _Behance: https://www.behance.net
.. _Bitbucket: https://bitbucket.org
.. _Box: https://www.box.com
.. _Clef: https://getclef.com/
.. _Dailymotion: https://dailymotion.com
.. _Disqus: https://disqus.com
.. _Douban: http://www.douban.com
Expand Down
15 changes: 15 additions & 0 deletions docs/backends/clef.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Clef
======

Clef works similar to Facebook (OAuth).

- Register a new application at `Clef Developers`_, set the callback URL to
``http://example.com/complete/clef/`` replacing ``example.com`` with your
domain.

- Fill ``App Id`` and ``App Secret`` values in the settings::

SOCIAL_AUTH_CLEF_KEY = ''
SOCIAL_AUTH_CLEF_SECRET = ''

.. _Clef Developers: https://getclef.com/developer
1 change: 1 addition & 0 deletions examples/django_example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
'social.backends.belgiumeid.BelgiumEIDOpenId',
'social.backends.bitbucket.BitbucketOAuth',
'social.backends.box.BoxOAuth2',
'social.backends.clef.ClefOAuth2',
'social.backends.coinbase.CoinbaseOAuth2',
'social.backends.dailymotion.DailymotionOAuth2',
'social.backends.disqus.DisqusOAuth2',
Expand Down
2 changes: 2 additions & 0 deletions examples/django_example/example/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -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' "clef" %}">Clef OAuth</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 />
Expand Down Expand Up @@ -66,6 +67,7 @@
<a href="{% url 'social:begin' 'yandex-oauth2' %}">Yandex OAuth2</a>
<a href="{% url 'social:begin' 'taobao' %}">TAOBAO OAuth2</a> <br />
<a href="{% url 'social:begin' 'vimeo' %}">Vimeo OAuth1</a> <br />
>>>>>>> 3aec8a973b809746ffdee33de39f55e64b293e9a

<a href="{% url 'social:begin' 'email' %}">Email Auth</a> <br />
<a href="{% url 'social:begin' 'username' %}">Username Auth</a> <br />
Expand Down
1 change: 1 addition & 0 deletions examples/django_me_example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
'social.backends.stocktwits.StocktwitsOAuth2',
'social.backends.tripit.TripItOAuth',
'social.backends.twilio.TwilioAuth',
'social.backends.clef.ClefOAuth2',
'social.backends.xing.XingOAuth',
'social.backends.yandex.YandexOAuth2',
'social.backends.douban.DoubanOAuth2',
Expand Down
1 change: 1 addition & 0 deletions examples/django_me_example/example/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<a href="{% url 'social:begin' "thisismyjam" %}">ThisIsMyJam OAuth1</a> <br />
<a href="{% url 'social:begin' "stocktwits" %}">Stocktwits OAuth2</a> <br />
<a href="{% url 'social:begin' "tripit" %}">Tripit OAuth</a> <br />
<a href="{% url 'social:begin' "clef" %}">Clef OAuth</a> <br />
<a href="{% url 'social:begin' "twilio" %}">Twilio</a> <br />
<a href="{% url 'social:begin' "xing" %}">Xing OAuth</a> <br />
<a href="{% url 'social:begin' "yandex-oauth2" %}">Yandex OAuth2</a> <br />
Expand Down
1 change: 1 addition & 0 deletions examples/flask_example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'social.backends.thisismyjam.ThisIsMyJamOAuth1',
'social.backends.stocktwits.StocktwitsOAuth2',
'social.backends.tripit.TripItOAuth',
'social.backends.tripit.ClefOAuth2',
'social.backends.twilio.TwilioAuth',
'social.backends.xing.XingOAuth',
'social.backends.yandex.YandexOAuth2',
Expand Down
1 change: 1 addition & 0 deletions examples/flask_example/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<a href="{{ url_for("social.auth", backend="thisismyjam") }}">ThisIsMyJam OAuth1</a> <br />
<a href="{{ url_for("social.auth", backend="stocktwits") }}">Stocktwits OAuth2</a> <br />
<a href="{{ url_for("social.auth", backend="tripit") }}">Tripit OAuth</a> <br />
<a href="{{ url_for("social.auth", backend="clef") }}">Clef OAuth2</a> <br />
<a href="{{ url_for("social.auth", backend="twilio") }}">Twilio</a> <br />
<a href="{{ url_for("social.auth", backend="xing") }}">Xing OAuth</a> <br />
<a href="{{ url_for("social.auth", backend="yandex-oauth2") }}">Yandex OAuth2</a> <br />
Expand Down
1 change: 1 addition & 0 deletions examples/pyramid_example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'social.backends.stocktwits.StocktwitsOAuth2',
'social.backends.tripit.TripItOAuth',
'social.backends.twilio.TwilioAuth',
'social.backends.tripit.ClefOAuth2',
'social.backends.xing.XingOAuth',
'social.backends.yandex.YandexOAuth2',
'social.backends.podio.PodioOAuth2',
Expand Down
1 change: 1 addition & 0 deletions examples/pyramid_example/example/templates/home.pt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<a href="${request.route_url('social.auth', backend='thisismyjam')}">ThisIsMyJam OAuth1</a> <br />
<a href="${request.route_url('social.auth', backend='stocktwits')}">Stocktwits OAuth2</a> <br />
<a href="${request.route_url('social.auth', backend='tripit')}">Tripit OAuth</a> <br />
<a href="${request.route_url('social.auth', backend='clef')}">Clef OAuth2</a> <br />
<a href="${request.route_url('social.auth', backend='twilio')}">Twilio</a> <br />
<a href="${request.route_url('social.auth', backend='xing')}">Xing OAuth</a> <br />
<a href="${request.route_url('social.auth', backend='yandex-oauth2')}">Yandex OAuth2</a> <br />
Expand Down
1 change: 1 addition & 0 deletions examples/tornado_example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'social.backends.thisismyjam.ThisIsMyJamOAuth1',
'social.backends.stocktwits.StocktwitsOAuth2',
'social.backends.tripit.TripItOAuth',
'social.backends.tripit.ClefOAuth2',
'social.backends.twilio.TwilioAuth',
'social.backends.xing.XingOAuth',
'social.backends.yandex.YandexOAuth2',
Expand Down
1 change: 1 addition & 0 deletions examples/tornado_example/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<a href="/login/thisismyjam">ThisIsMyJam OAuth1</a> <br />
<a href="/login/stocktwits">Stocktwits OAuth2</a> <br />
<a href="/login/tripit">Tripit OAuth</a> <br />
<a href="/login/clef">Clef OAuth2</a> <br />
<a href="/login/twilio">Twilio</a> <br />
<a href="/login/xing">Xing OAuth</a> <br />
<a href="/login/yandex-oauth2">Yandex OAuth2</a> <br />
Expand Down
1 change: 1 addition & 0 deletions examples/webpy_example/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'social.backends.thisismyjam.ThisIsMyJamOAuth1',
'social.backends.stocktwits.StocktwitsOAuth2',
'social.backends.tripit.TripItOAuth',
'social.backends.tripit.ClefOAuth2',
'social.backends.twilio.TwilioAuth',
'social.backends.xing.XingOAuth',
'social.backends.yandex.YandexOAuth2',
Expand Down
1 change: 1 addition & 0 deletions examples/webpy_example/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<a href="/login/thisismyjam/">ThisIsMyJamm OAuth1</a> <br />
<a href="/login/stocktwits/">Stocktwits OAuth2</a> <br />
<a href="/login/tripit/">Tripit OAuth</a> <br />
<a href="/login/clef/">Clef OAuth2</a> <br />
<a href="/login/twilio/">Twilio</a> <br />
<a href="/login/xing/">Xing OAuth</a> <br />
<a href="/login/yandex-oauth2/">Yandex OAuth2</a> <br />
Expand Down
48 changes: 48 additions & 0 deletions social/backends/clef.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Clef OAuth support.

This contribution adds support for Clef OAuth service. The settings
SOCIAL_AUTH_CLEF_KEY and SOCIAL_AUTH_CLEF_SECRET must be defined with the values
given by Clef application registration process.
"""

import json
import urllib2
from social.backends.oauth import BaseOAuth2

class ClefOAuth2(BaseOAuth2):
"""Clef OAuth authentication backend"""
name = 'clef'
AUTHORIZATION_URL = 'https://clef.io/iframes/qr'
ACCESS_TOKEN_URL = 'https://clef.io/api/v1/authorize'
INFO_URL = 'https://clef.io/api/v1/info'
ACCESS_TOKEN_METHOD = "POST"
SCOPE_SEPARATOR = ','
EXTRA_DATA = [
('id', 'id')
]

def auth_params(self, *args, **kwargs):
params = super(ClefOAuth2, self).auth_params(*args, **kwargs)
params['app_id'] = params.pop('client_id')
params['redirect_url'] = params.pop('redirect_uri')
return params


def get_user_details(self, response):
"""Return user details from Github account"""
info = response.get('info')
return {
'username': response.get('clef_id'),
'email': info.get('email', ''),
'first_name': info.get('first_name'),
'last_name': info.get('last_name'),
'phone_number': info.get('phone_number', '')
}

def user_data(self, access_token, *args, **kwargs):
url = '%s?access_token=%s' % (self.INFO_URL, access_token)
try:
return json.load(urllib2.urlopen(url))
except ValueError:
return None
29 changes: 29 additions & 0 deletions social/tests/backends/test_clef.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import json

from httpretty import HTTPretty

from social.exceptions import AuthFailed

from social.tests.backends.oauth import OAuth2Test

class ClefOAuth2Test(OAuth2Test):
backend_path = 'social.backends.clef.ClefOAuth2'
user_data_url = 'https://clef.io/api/v1/info'
expected_username = '123456789'
access_token_body = json.dumps({
'access_token': 'foobar'
})
user_data_body = json.dumps({
'info': {
'first_name': 'Test',
'last_name': 'User',
'email': 'test@example.com'
},
'clef_id': '123456789'
})

def test_login(self):
self.do_login()

def test_partial_pipeline(self):
self.do_partial_pipeline()