def oauth2callback():
"""Authenticates google user and authorizes app"""
logging.basicConfig(filename='debug.log', level=logging.WARNING)
flow = flow_from_clientsecrets(
'client_secret.json',
scope='https://www.googleapis.com/auth/calendar.readonly \
https://www.googleapis.com/auth/plus.login',
redirect_uri=url_for('oauth2callback', _external=True))
flow.params['access_type'] = 'online'
flow.params['approval_prompt'] = 'auto'
if 'code' not in request.args:
auth_uri = flow.step1_get_authorize_url()
return redirect(auth_uri)
else:
auth_code = request.args.get('code')
credentials = flow.step2_exchange(auth_code) # creates credentials object
session['credentials'] = credentials.to_json()
return redirect(url_for('oauth2'))
评论列表
文章目录