[Python-modules-commits] [python-social-auth] 117/322: add qiita backend
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Dec 24 15:12:57 UTC 2016
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to tag v0.2.10
in repository python-social-auth.
commit 4c731dee079a5a6771e9c36ab628d5cb20397efd
Author: tell-k <ffk2005 at gmail.com>
Date: Wed Feb 11 21:15:48 2015 +0900
add qiita backend
---
docs/backends/qiita.rst | 19 +++++++++++
social/backends/qiita.py | 66 +++++++++++++++++++++++++++++++++++++
social/tests/backends/test_qiita.py | 25 ++++++++++++++
3 files changed, 110 insertions(+)
diff --git a/docs/backends/qiita.rst b/docs/backends/qiita.rst
new file mode 100644
index 0000000..b1cd5dd
--- /dev/null
+++ b/docs/backends/qiita.rst
@@ -0,0 +1,19 @@
+Qiita
+=====
+
+Qiita
+
+- Register a new application at `https://qiita.com/settings/applications`_, set the
+ callback URL to ``http://example.com/complete/qiita/`` replacing
+ ``example.com`` with your domain.
+
+- Fill ``Client ID`` and ``Client Secret`` values in the settings::
+
+ SOCIAL_AUTH_QIITA_KEY = ''
+ SOCIAL_AUTH_QIITA_SECRET = ''
+
+- Also it's possible to define extra permissions with::
+
+ SOCIAL_AUTH_QIITA_SCOPE = [...]
+
+ See auth scopes at https://qiita.com/api/v2/docs#スコープ
diff --git a/social/backends/qiita.py b/social/backends/qiita.py
new file mode 100644
index 0000000..05a0e47
--- /dev/null
+++ b/social/backends/qiita.py
@@ -0,0 +1,66 @@
+"""
+Qiita OAuth2 backend, docs at:
+ http://psa.matiasaguirre.net/docs/backends/qiita.html
+ http://qiita.com/api/v2/docs#get-apiv2oauthauthorize
+"""
+import json
+
+from social.backends.oauth import BaseOAuth2
+
+
+class QiitaOAuth2(BaseOAuth2):
+ """Qiita OAuth authentication backend"""
+ name = 'qiita'
+
+ AUTHORIZATION_URL = 'https://qiita.com/api/v2/oauth/authorize'
+ ACCESS_TOKEN_URL = 'https://qiita.com/api/v2/access_tokens'
+ ACCESS_TOKEN_METHOD = 'POST'
+ SCOPE_SEPARATOR = ' '
+ REDIRECT_STATE = True
+ EXTRA_DATA = [
+ ('description', 'description'),
+ ('facebook_id', 'facebook_id'),
+ ('followees_count', 'followers_count'),
+ ('followers_count', 'followers_count'),
+ ('github_login_name', 'github_login_name'),
+ ('id', 'id'),
+ ('items_count', 'items_count'),
+ ('linkedin_id', 'linkedin_id'),
+ ('location', 'location'),
+ ('name', 'name'),
+ ('organization', 'organization'),
+ ('profile_image_url', 'profile_image_url'),
+ ('twitter_screen_name', 'twitter_screen_name'),
+ ('website_url', 'website_url'),
+ ]
+
+ def auth_complete_params(self, state=None):
+ data = super(QiitaOAuth2, self).auth_complete_params(state)
+ if "grant_type" in data:
+ del data["grant_type"]
+ if "redirect_uri" in data:
+ del data["redirect_uri"]
+ return json.dumps(data)
+
+ def auth_headers(self):
+ return {'Content-Type': 'application/json'}
+
+ def request_access_token(self, *args, **kwargs):
+ data = super(QiitaOAuth2, self).request_access_token(*args, **kwargs)
+ data.update({'access_token': data['token']})
+ return data
+
+ def get_user_details(self, response):
+ """Return user details from Qiita account"""
+ return {
+ 'username': response['id'],
+ 'fullname': response['name'],
+ }
+
+ def user_data(self, access_token, *args, **kwargs):
+ """Loads user data from service"""
+ return self.get_json(
+ 'https://qiita.com/api/v2/authenticated_user',
+ headers={
+ 'Authorization': ' Bearer {}'.format(access_token)
+ })
diff --git a/social/tests/backends/test_qiita.py b/social/tests/backends/test_qiita.py
new file mode 100644
index 0000000..b1871d7
--- /dev/null
+++ b/social/tests/backends/test_qiita.py
@@ -0,0 +1,25 @@
+import json
+
+from social.tests.backends.oauth import OAuth2Test
+
+
+class QiitaOAuth2Test(OAuth2Test):
+ backend_path = 'social.backends.qiita.QiitaOAuth2'
+ user_data_url = 'https://qiita.com/api/v2/authenticated_user'
+ expected_username = 'foobar'
+
+ access_token_body = json.dumps({
+ 'token': 'foobar',
+ 'token_type': 'bearer'
+ })
+
+ user_data_body = json.dumps({
+ 'id': 'foobar',
+ 'name': 'Foo Bar'
+ })
+
+ def test_login(self):
+ self.do_login()
+
+ def test_partial_pipeline(self):
+ self.do_partial_pipeline()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-social-auth.git
More information about the Python-modules-commits
mailing list