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,29 @@
"""
Provider for Patreon
"""
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class VimeoOAuth2Account(ProviderAccount):
pass
class VimeoOAuth2Provider(OAuth2Provider):
id = "vimeo_oauth2"
name = "Vimeo"
account_class = VimeoOAuth2Account
def get_default_scope(self):
return ["public", "private"]
def extract_uid(self, data):
return data.get("uri").split("/")[-1]
def extract_common_fields(self, data):
return {
"fullname": data.get("name"),
}
provider_classes = [VimeoOAuth2Provider]

View File

@@ -0,0 +1,32 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import VimeoOAuth2Provider
class VimeoOAuth2Tests(OAuth2TestsMixin, TestCase):
provider_id = VimeoOAuth2Provider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""{
"uri": "/users/12345",
"name": "AllAuth",
"link": "https://vimeo.com/user12345",
"created_time": "2012-06-04T00:02:16+00:00",
"pictures": {
"uri": null,
"active": false,
"type": "default",
"sizes": [{
"width": 30,
"height": 30,
"link": "https://i.vimeocdn.com/portrait/defaults-blue_30x30.png"
}],
"resource_key": "1234567890abcdef"
},
"resource_key": "1234567890abcdef",
"account": "pro"
}""",
) # noqa

View File

@@ -0,0 +1,8 @@
"""URLs for Patreon Provider"""
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns
from .provider import VimeoOAuth2Provider
urlpatterns = default_urlpatterns(VimeoOAuth2Provider)

View File

@@ -0,0 +1,33 @@
"""
Views for PatreonProvider
https://www.patreon.com/platform/documentation/oauth
"""
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import VimeoOAuth2Provider
class VimeoOAuth2Adapter(OAuth2Adapter):
provider_id = VimeoOAuth2Provider.id
access_token_url = "https://api.vimeo.com/oauth/access_token"
authorize_url = "https://api.vimeo.com/oauth/authorize"
profile_url = "https://api.vimeo.com/me/"
def complete_login(self, request, app, token, **kwargs):
resp = requests.get(
self.profile_url,
headers={"Authorization": "Bearer " + token.token},
)
extra_data = resp.json()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(VimeoOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(VimeoOAuth2Adapter)