Flask - 重定向到Google authrozie url Origin null

时间:2016-05-22 18:25:41

标签: python flask google-api

我试图从谷歌api获取日历事件。 (Flask API和Angular)

问题是,当我将用户重定向到授权网址(使用 step1_get_authorize_url 方法)时,原始标头为空,我一直得到No' Access-Control-允许来源'标题错误。

@oauth_api.route('/google/<action>')
def getGoogleCalendarRequest(action):
    if 'credentials' not in session:
         return redirect(url_for('oauth_controller.google'+action.title()+'Callback'))

    credentials = client.OAuth2Credentials.from_json(session['credentials'])

    if credentials.access_token_expired:
        return redirect(url_for('oauth_controller.google'+action.title()+'Callback'))
    else:
        return session['credentials'] 

@oauth_api.route('/googleCallback')
def googleCalendarCallback():
    flow = client.OAuth2WebServerFlow(
    client_id='client_id',
    client_secret='client_secret',
    scope='https://www.googleapis.com/auth/calendar.readonly',
    redirect_uri=url_for('oauth_controller.googleCalendarCallback', 
    approval_prompt='force',
    access_type='offline'))

    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)
        session['credentials'] = credentials.to_json()

    return redirect(url_for('oauth_controller.getGoogleCalendarRequest'))

0 个答案:

没有答案