-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoauth.py
More file actions
51 lines (43 loc) · 1.63 KB
/
Copy pathoauth.py
File metadata and controls
51 lines (43 loc) · 1.63 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
import logging
from rauth import OAuth2Service
from flask import current_app, url_for, request, redirect, session
class OAuthSession(object):
def __init__(self):
self.credentials = current_app.config['OAUTH_CREDENTIALS']
self.service = OAuth2Service(
**self.credentials
)
def callback(self):
def decode_json(payload):
return json.loads(payload.decode('utf-8'))
self.session = self.service.get_auth_session(
data={'code': request.args['code'],
'grant_type': 'authorization_code',
'redirect_uri': OAuthSession.get_callback_url()},
decoder=decode_json
)
@staticmethod
def authorize():
session = OAuthSession()
return redirect(session.service.get_authorize_url(
scope='email ' +
'profile ' +
'openid ' +
'https://www.googleapis.com/auth/fitness.activity.read ' +
'https://www.googleapis.com/auth/fitness.body.read ' +
'https://www.googleapis.com/auth/fitness.location.read',
response_type='code',
redirect_uri=OAuthSession.get_callback_url())
)
def get(self, request):
return self.session.get(request).json()
def post(self, request, data):
return self.session.post(request, json=data).json()
@staticmethod
def get_callback_url():
# return url_for('auth_success',
# _external=True)
logging.info('Request: 111')
return url_for('auth_success',
_external=True)