Debian Codegraph @

allauth/socialaccount/providers/windowslive/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 WindowsLiveOAuth2Adapter(OAuth2Adapter):
14 provider_id = "windowslive"
15 access_token_url = "https://login.live.com/oauth20_token.srf" # nosec
16 authorize_url = "https://login.live.com/oauth20_authorize.srf"
17 profile_url = "https://apis.live.net/v5.0/me"
18
19 def complete_login(self, request: HttpRequest, app, token, **kwargs):
20 # example of what's returned (in python format):
21 # {'first_name': 'James', 'last_name': 'Smith',
22 # 'name': 'James Smith', 'locale': 'en_US', 'gender': None,
23 # 'emails': {'personal': None, 'account': '[email protected]',
24 # 'business': None, 'preferred': '[email protected]'},
25 # 'link': 'https://profile.live.com/',
26 # 'updated_time': '2014-02-07T00:35:27+0000',
27 # 'id': '83605e110af6ff98'}
28
29 with get_adapter().get_requests_session() as sess:
30 headers = {"Authorization": f"Bearer {token.token}"}
31 resp = sess.get(self.profile_url, headers=headers)
32 resp.raise_for_status()
33 extra_data = resp.json()
34 return self.get_provider().sociallogin_from_response(request, extra_data)
35
36
37 oauth2_login = OAuth2LoginView.adapter_view(WindowsLiveOAuth2Adapter)
38 oauth2_callback = OAuth2CallbackView.adapter_view(WindowsLiveOAuth2Adapter)