This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1 @@
__author__ = "jshedd"

View File

@@ -0,0 +1,29 @@
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth.provider import OAuthProvider
class TumblrAccount(ProviderAccount):
def get_profile_url_(self):
return "http://%s.tumblr.com/" % self.account.extra_data.get("name")
def to_str(self):
dflt = super(TumblrAccount, self).to_str()
name = self.account.extra_data.get("name", dflt)
return name
class TumblrProvider(OAuthProvider):
id = "tumblr"
name = "Tumblr"
account_class = TumblrAccount
def extract_uid(self, data):
return data["name"]
def extract_common_fields(self, data):
return dict(
first_name=data.get("name"),
)
provider_classes = [TumblrProvider]

View File

@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from allauth.socialaccount.tests import OAuthTestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import TumblrProvider
class TumblrTests(OAuthTestsMixin, TestCase):
provider_id = TumblrProvider.id
def get_mocked_response(self):
return [
MockedResponse(
200,
"""
{
"meta": {
"status": 200,
"msg": "OK"
},
"response": {
"user": {
"following": 263,
"default_post_format": "html",
"name": "derekg",
"likes": 606,
"blogs": [
{
"name": "derekg",
"title": "Derek Gottfrid",
"url": "http://derekg.org/",
"tweet": "auto",
"primary": true,
"followers": 33004929
},
{
"name": "ihatehipstrz",
"title": "I Hate Hipstrz"
}
]
}
} }
""",
)
]

View File

@@ -0,0 +1,6 @@
from allauth.socialaccount.providers.oauth.urls import default_urlpatterns
from .provider import TumblrProvider
urlpatterns = default_urlpatterns(TumblrProvider)

View File

@@ -0,0 +1,34 @@
import json
from allauth.socialaccount.providers.oauth.client import OAuth
from allauth.socialaccount.providers.oauth.views import (
OAuthAdapter,
OAuthCallbackView,
OAuthLoginView,
)
from .provider import TumblrProvider
class TumblrAPI(OAuth):
url = "http://api.tumblr.com/v2/user/info"
def get_user_info(self):
data = json.loads(self.query(self.url))
return data["response"]["user"]
class TumblrOAuthAdapter(OAuthAdapter):
provider_id = TumblrProvider.id
request_token_url = "https://www.tumblr.com/oauth/request_token"
access_token_url = "https://www.tumblr.com/oauth/access_token"
authorize_url = "https://www.tumblr.com/oauth/authorize"
def complete_login(self, request, app, token, response):
client = TumblrAPI(request, app.client_id, app.secret, self.request_token_url)
extra_data = client.get_user_info()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth_login = OAuthLoginView.adapter_view(TumblrOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(TumblrOAuthAdapter)