Debian Codegraph @

allauth/socialaccount/providers/stocktwits/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 StocktwitsOAuth2Adapter(OAuth2Adapter):
14 provider_id = "stocktwits"
15 access_token_url = "https://api.stocktwits.com/api/2/oauth/token" # nosec
16 authorize_url = "https://api.stocktwits.com/api/2/oauth/authorize"
17 profile_url = "https://api.stocktwits.com/api/2/streams/user/{user}.json"
18 scope_delimiter = ","
19
20 def complete_login(self, request: HttpRequest, app, token, **kwargs):
21 response: dict = kwargs["response"]
22 user_id = response.get("user_id")
23 with get_adapter().get_requests_session() as sess:
24 resp = sess.get(self.profile_url.format(user=user_id))
25 resp.raise_for_status()
26 extra_data = resp.json()
27 return self.get_provider().sociallogin_from_response(request, extra_data)
28
29
30 oauth2_login = OAuth2LoginView.adapter_view(StocktwitsOAuth2Adapter)
31 oauth2_callback = OAuth2CallbackView.adapter_view(StocktwitsOAuth2Adapter)