Debian Codegraph @

allauth/socialaccount/providers/foursquare/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 FoursquareOAuth2Adapter(OAuth2Adapter):
14 provider_id = "foursquare"
15 access_token_url = "https://foursquare.com/oauth2/access_token" # nosec
16 # Issue ?? -- this one authenticates over and over again...
17 # authorize_url = 'https://foursquare.com/oauth2/authorize'
18 authorize_url = "https://foursquare.com/oauth2/authenticate"
19 profile_url = "https://api.foursquare.com/v2/users/self"
20
21 def complete_login(self, request: HttpRequest, app, token, **kwargs):
22 # Foursquare needs a version number for their API requests as
23 # documented here
24 # https://developer.foursquare.com/overview/versioning
25 with get_adapter().get_requests_session() as sess:
26 params = {"oauth_token": token.token, "v": "20140116"}
27 resp = sess.get(self.profile_url, params=params)
28 extra_data = resp.json()["response"]["user"]
29 return self.get_provider().sociallogin_from_response(request, extra_data)
30
31
32 oauth2_login = OAuth2LoginView.adapter_view(FoursquareOAuth2Adapter)
33 oauth2_callback = OAuth2CallbackView.adapter_view(FoursquareOAuth2Adapter)