Debian Codegraph @

allauth/socialaccount/providers/untappd/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 .client import UntappdOAuth2Client
13
14
15 class UntappdOAuth2Adapter(OAuth2Adapter):
16 client_class = UntappdOAuth2Client
17 provider_id = "untappd"
18 access_token_url = "https://untappd.com/oauth/authorize/" # nosec
19 access_token_method = "GET" # nosec
20 authorize_url = "https://untappd.com/oauth/authenticate/"
21 user_info_url = "https://api.untappd.com/v4/user/info/"
22
23 def complete_login(self, request: HttpRequest, app, token, **kwargs):
24 with get_adapter().get_requests_session() as sess:
25 resp = sess.get(self.user_info_url, params={"access_token": token.token})
26 extra_data = resp.json()
27 # TODO: get and store the email from the user info json
28 return self.get_provider().sociallogin_from_response(request, extra_data)
29
30
31 oauth2_login = OAuth2LoginView.adapter_view(UntappdOAuth2Adapter)
32 oauth2_callback = OAuth2CallbackView.adapter_view(UntappdOAuth2Adapter)