Debian Codegraph @

allauth/socialaccount/providers/klaviyo/views.py

raw
1 from __future__ import annotations
2
3 from allauth.socialaccount.adapter import get_adapter
4 from allauth.socialaccount.models import SocialToken
5 from allauth.socialaccount.providers.oauth2.views import (
6 OAuth2Adapter,
7 OAuth2CallbackView,
8 OAuth2LoginView,
9 )
10
11
12 KLAVIYO_API_VERSION = "2026-01-15"
13
14
15 class KlaviyoOAuth2Adapter(OAuth2Adapter):
16 provider_id = "klaviyo"
17 basic_auth = True
18
19 access_token_url = "https://a.klaviyo.com/oauth/token" # nosec
20 authorize_url = "https://www.klaviyo.com/oauth/authorize" # nosec
21 accounts_url = "https://a.klaviyo.com/api/accounts/"
22
23 def complete_login(self, request, app, token: SocialToken, **kwargs):
24 with get_adapter().get_requests_session() as sess:
25 r = sess.get(
26 self.accounts_url,
27 headers={
28 "accept": "application/vnd.api+json",
29 "content-type": "application/vnd.api+json",
30 "revision": KLAVIYO_API_VERSION,
31 "Authorization": f"Bearer {token.token}",
32 },
33 )
34 r.raise_for_status()
35 extra_data = r.json()
36 return self.get_provider().sociallogin_from_response(request, extra_data)
37
38
39 oauth2_login = OAuth2LoginView.adapter_view(KlaviyoOAuth2Adapter)
40 oauth2_callback = OAuth2CallbackView.adapter_view(KlaviyoOAuth2Adapter)