Debian Codegraph @

allauth/socialaccount/providers/box/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 BoxOAuth2Adapter(OAuth2Adapter):
14 provider_id = "box"
15 access_token_url = "https://api.box.com/oauth2/token" # nosec
16 authorize_url = "https://account.box.com/api/oauth2/authorize"
17 profile_url = "https://api.box.com/2.0/users/me"
18 redirect_uri_protocol = None
19
20 def complete_login(self, request: HttpRequest, app, token, **kwargs):
21 with get_adapter().get_requests_session() as sess:
22 resp = sess.get(self.profile_url, params={"access_token": token.token})
23
24 # This only here because of weird response from the test suite
25 if isinstance(resp, list):
26 resp = resp[0]
27
28 extra_data = resp.json()
29
30 return self.get_provider().sociallogin_from_response(request, extra_data)
31
32
33 oauth_login = OAuth2LoginView.adapter_view(BoxOAuth2Adapter)
34 oauth_callback = OAuth2CallbackView.adapter_view(BoxOAuth2Adapter)