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,40 @@
from __future__ import unicode_literals
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class FeedlyAccount(ProviderAccount):
def get_avatar_url(self):
return self.account.extra_data.get("picture")
def to_str(self):
name = "{0} {1}".format(
self.account.extra_data.get("givenName", ""),
self.account.extra_data.get("familyName", ""),
)
if name.strip() != "":
return name
return super(FeedlyAccount, self).to_str()
class FeedlyProvider(OAuth2Provider):
id = str("feedly")
name = "Feedly"
account_class = FeedlyAccount
def get_default_scope(self):
return ["https://cloud.feedly.com/subscriptions"]
def extract_uid(self, data):
return str(data["id"])
def extract_common_fields(self, data):
return dict(
email=data.get("email"),
last_name=data.get("familyName"),
first_name=data.get("givenName"),
)
provider_classes = [FeedlyProvider]

View File

@@ -0,0 +1,28 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import FeedlyProvider
class FeedlyTests(OAuth2TestsMixin, TestCase):
provider_id = FeedlyProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""
{
"id": "c805fcbf-3acf-4302-a97e-d82f9d7c897f",
"email": "jim.smith@example.com",
"givenName": "Jim",
"familyName": "Smith",
"picture": "https://www.google.com/profile_images/1771656873/bigger.jpg",
"gender": "male",
"locale": "en",
"reader": "9080770707070700",
"google": "115562565652656565656",
"twitter": "jimsmith",
"facebook": "",
"wave": "2013.7"
}""",
)

View File

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

View File

@@ -0,0 +1,30 @@
from __future__ import unicode_literals
import requests
from allauth.socialaccount import app_settings
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import FeedlyProvider
class FeedlyOAuth2Adapter(OAuth2Adapter):
provider_id = FeedlyProvider.id
host = app_settings.PROVIDERS.get(provider_id, {}).get("HOST", "cloud.feedly.com")
access_token_url = "https://%s/v3/auth/token" % host
authorize_url = "https://%s/v3/auth/auth" % host
profile_url = "https://%s/v3/profile" % host
def complete_login(self, request, app, token, **kwargs):
headers = {"Authorization": "OAuth {0}".format(token.token)}
resp = requests.get(self.profile_url, headers=headers)
extra_data = resp.json()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(FeedlyOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(FeedlyOAuth2Adapter)