Debian Codegraph @

allauth/socialaccount/providers/fxa/views.py

raw
1 from __future__ import annotations
2
3 from django.http import HttpRequest
4
5 from allauth.socialaccount.adapter import get_adapter
6 from allauth.socialaccount.providers.oauth2.views import (
7 OAuth2Adapter,
8 OAuth2CallbackView,
9 OAuth2LoginView,
10 )
11
12 from .constants import FXA_OAUTH_ENDPOINT, FXA_PROFILE_ENDPOINT, PROVIDER_ID
13
14
15 class FirefoxAccountsOAuth2Adapter(OAuth2Adapter):
16 provider_id = PROVIDER_ID
17 access_token_url = f"{FXA_OAUTH_ENDPOINT}/token"
18 authorize_url = f"{FXA_OAUTH_ENDPOINT}/authorization"
19 profile_url = f"{FXA_PROFILE_ENDPOINT}/profile"
20
21 def complete_login(self, request: HttpRequest, app, token, **kwargs):
22 headers = {"Authorization": f"Bearer {token.token}"}
23 with get_adapter().get_requests_session() as sess:
24 resp = sess.get(self.profile_url, headers=headers)
25 extra_data = resp.json()
26 return self.get_provider().sociallogin_from_response(request, extra_data)
27
28
29 oauth2_login = OAuth2LoginView.adapter_view(FirefoxAccountsOAuth2Adapter)
30 oauth2_callback = OAuth2CallbackView.adapter_view(FirefoxAccountsOAuth2Adapter)