| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from django.http import HttpRequest |
| 4 |
|
| 5 |
from allauth.socialaccount.providers.oauth.client import OAuth |
| 6 |
from allauth.socialaccount.providers.oauth.views import ( |
| 7 |
OAuthAdapter, |
| 8 |
OAuthCallbackView, |
| 9 |
OAuthLoginView, |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
class VimeoAPI(OAuth): |
| 14 |
url = "https://vimeo.com/api/rest/v2?method=vimeo.people.getInfo" |
| 15 |
|
| 16 |
def get_user_info(self): |
| 17 |
url = self.url |
| 18 |
data = self.query(url, params=dict(format="json")).json() |
| 19 |
return data["person"] |
| 20 |
|
| 21 |
|
| 22 |
class VimeoOAuthAdapter(OAuthAdapter): |
| 23 |
provider_id = "vimeo" |
| 24 |
request_token_url = "https://vimeo.com/oauth/request_token" # nosec |
| 25 |
access_token_url = "https://vimeo.com/oauth/access_token" # nosec |
| 26 |
authorize_url = "https://vimeo.com/oauth/authorize" |
| 27 |
|
| 28 |
def complete_login(self, request: HttpRequest, app, token, **kwargs): |
| 29 |
client = VimeoAPI(request, app.client_id, app.secret, self.request_token_url) |
| 30 |
extra_data = client.get_user_info() |
| 31 |
return self.get_provider().sociallogin_from_response(request, extra_data) |
| 32 |
|
| 33 |
|
| 34 |
oauth_login = OAuthLoginView.adapter_view(VimeoOAuthAdapter) |
| 35 |
oauth_callback = OAuthCallbackView.adapter_view(VimeoOAuthAdapter) |