-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathoauth.py
More file actions
29 lines (23 loc) · 997 Bytes
/
oauth.py
File metadata and controls
29 lines (23 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from typing import Dict
import requests
from django.conf import settings
from authlib.integrations.requests_client import OAuth2Session
class OAuthManager(object):
def __init__(self):
self.client_id = settings.SOCIAL_AUTH_DRYCC_KEY
self.client_secret = settings.SOCIAL_AUTH_DRYCC_SECRET
self.token_url = settings.SOCIAL_AUTH_DRYCC_ACCESS_TOKEN_URL
self.api_url = settings.SOCIAL_AUTH_DRYCC_ACCESS_API_URL
self.client = OAuth2Session(self.client_id, self.client_secret)
def get_user_by_token(self, token: str) -> Dict:
response = requests.get(f'{self.api_url}/user/info/', headers={
'Authorization': f'Bearer {token}'
})
result = response.json()
return result
def get_email_by_token(self, token: str) -> Dict:
response = requests.get(f'{self.api_url}/user/email/', headers={
'Authorization': f'Bearer {token}'
})
result = response.json()
return result