Debian Codegraph @

allauth/socialaccount/providers/atlassian/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.models import SocialToken
7 from allauth.socialaccount.providers.oauth2.views import (
8 OAuth2Adapter,
9 OAuth2CallbackView,
10 OAuth2LoginView,
11 )
12
13
14 class AtlassianOAuth2Adapter(OAuth2Adapter):
15 provider_id = "atlassian"
16 access_token_url = "https://api.atlassian.com/oauth/token" # nosec
17 authorize_url = "https://auth.atlassian.com/authorize"
18 profile_url = "https://api.atlassian.com/me"
19
20 def complete_login(self, request: HttpRequest, app, token: SocialToken, **kwargs):
21 headers = {
22 "Authorization": f"Bearer {token.token}",
23 "Accept": "application/json",
24 }
25 with get_adapter().get_requests_session() as sess:
26 response = sess.get(self.profile_url, headers=headers)
27 response.raise_for_status()
28 data = response.json()
29 return self.get_provider().sociallogin_from_response(request, data)
30
31
32 oauth2_login = OAuth2LoginView.adapter_view(AtlassianOAuth2Adapter)
33 oauth2_callback = OAuth2CallbackView.adapter_view(AtlassianOAuth2Adapter)