Debian Codegraph @

allauth/socialaccount/providers/amazon/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
13 class AmazonOAuth2Adapter(OAuth2Adapter):
14 provider_id = "amazon"
15 access_token_url = "https://api.amazon.com/auth/o2/token" # nosec
16 authorize_url = "https://www.amazon.com/ap/oa"
17 profile_url = "https://api.amazon.com/user/profile"
18
19 def complete_login(self, request: HttpRequest, app, token, **kwargs):
20 with get_adapter().get_requests_session() as sess:
21 response = sess.get(self.profile_url, params={"access_token": token.token})
22 response.raise_for_status()
23 extra_data = response.json()
24 if "Profile" in extra_data:
25 extra_data = {
26 "user_id": extra_data["Profile"]["CustomerId"],
27 "name": extra_data["Profile"]["Name"],
28 "email": extra_data["Profile"]["PrimaryEmail"],
29 }
30 return self.get_provider().sociallogin_from_response(request, extra_data)
31
32
33 oauth2_login = OAuth2LoginView.adapter_view(AmazonOAuth2Adapter)
34 oauth2_callback = OAuth2CallbackView.adapter_view(AmazonOAuth2Adapter)